<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/opencv2/core/operations.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">usr/include/opencv2/core</a> - operations.hpp<span style="font-size: 80%;"> (source / <a href="operations.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">4</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntryHi">-</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : /*M///////////////////////////////////////////////////////////////////////////////////////</a>
<span class="lineNum">       2 </span>            : //
<span class="lineNum">       3 </span>            : //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
<span class="lineNum">       4 </span>            : //
<span class="lineNum">       5 </span>            : //  By downloading, copying, installing or using the software you agree to this license.
<span class="lineNum">       6 </span>            : //  If you do not agree to this license, do not download, install,
<span class="lineNum">       7 </span>            : //  copy or use the software.
<span class="lineNum">       8 </span>            : //
<span class="lineNum">       9 </span>            : //
<span class="lineNum">      10 </span>            : //                           License Agreement
<span class="lineNum">      11 </span>            : //                For Open Source Computer Vision Library
<span class="lineNum">      12 </span>            : //
<span class="lineNum">      13 </span>            : // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
<span class="lineNum">      14 </span>            : // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
<span class="lineNum">      15 </span>            : // Third party copyrights are property of their respective owners.
<span class="lineNum">      16 </span>            : //
<span class="lineNum">      17 </span>            : // Redistribution and use in source and binary forms, with or without modification,
<span class="lineNum">      18 </span>            : // are permitted provided that the following conditions are met:
<span class="lineNum">      19 </span>            : //
<span class="lineNum">      20 </span>            : //   * Redistribution's of source code must retain the above copyright notice,
<span class="lineNum">      21 </span>            : //     this list of conditions and the following disclaimer.
<span class="lineNum">      22 </span>            : //
<span class="lineNum">      23 </span>            : //   * Redistribution's in binary form must reproduce the above copyright notice,
<span class="lineNum">      24 </span>            : //     this list of conditions and the following disclaimer in the documentation
<span class="lineNum">      25 </span>            : //     and/or other materials provided with the distribution.
<span class="lineNum">      26 </span>            : //
<span class="lineNum">      27 </span>            : //   * The name of the copyright holders may not be used to endorse or promote products
<span class="lineNum">      28 </span>            : //     derived from this software without specific prior written permission.
<span class="lineNum">      29 </span>            : //
<span class="lineNum">      30 </span>            : // This software is provided by the copyright holders and contributors &quot;as is&quot; and
<span class="lineNum">      31 </span>            : // any express or implied warranties, including, but not limited to, the implied
<span class="lineNum">      32 </span>            : // warranties of merchantability and fitness for a particular purpose are disclaimed.
<span class="lineNum">      33 </span>            : // In no event shall the Intel Corporation or contributors be liable for any direct,
<span class="lineNum">      34 </span>            : // indirect, incidental, special, exemplary, or consequential damages
<span class="lineNum">      35 </span>            : // (including, but not limited to, procurement of substitute goods or services;
<span class="lineNum">      36 </span>            : // loss of use, data, or profits; or business interruption) however caused
<span class="lineNum">      37 </span>            : // and on any theory of liability, whether in contract, strict liability,
<span class="lineNum">      38 </span>            : // or tort (including negligence or otherwise) arising in any way out of
<span class="lineNum">      39 </span>            : // the use of this software, even if advised of the possibility of such damage.
<span class="lineNum">      40 </span>            : //
<span class="lineNum">      41 </span>            : //M*/
<span class="lineNum">      42 </span>            : 
<span class="lineNum">      43 </span>            : #ifndef __OPENCV_CORE_OPERATIONS_HPP__
<span class="lineNum">      44 </span>            : #define __OPENCV_CORE_OPERATIONS_HPP__
<span class="lineNum">      45 </span>            : 
<span class="lineNum">      46 </span>            : #ifndef SKIP_INCLUDES
<span class="lineNum">      47 </span>            :   #include &lt;string.h&gt;
<span class="lineNum">      48 </span>            :   #include &lt;limits.h&gt;
<span class="lineNum">      49 </span>            : #endif // SKIP_INCLUDES
<span class="lineNum">      50 </span>            : 
<span class="lineNum">      51 </span>            : 
<span class="lineNum">      52 </span>            : #ifdef __cplusplus
<span class="lineNum">      53 </span>            : 
<span class="lineNum">      54 </span>            : /////// exchange-add operation for atomic operations on reference counters ///////
<span class="lineNum">      55 </span>            : #if defined __INTEL_COMPILER &amp;&amp; !(defined WIN32 || defined _WIN32)   // atomic increment on the linux version of the Intel(tm) compiler
<span class="lineNum">      56 </span>            :   #define CV_XADD(addr,delta) _InterlockedExchangeAdd(const_cast&lt;void*&gt;(reinterpret_cast&lt;volatile void*&gt;(addr)), delta)
<span class="lineNum">      57 </span>            : #elif defined __GNUC__
<span class="lineNum">      58 </span>            : 
<span class="lineNum">      59 </span>            :   #if defined __clang__ &amp;&amp; __clang_major__ &gt;= 3 &amp;&amp; !defined __ANDROID__ &amp;&amp; !defined __EMSCRIPTEN__
<span class="lineNum">      60 </span>            :     #ifdef __ATOMIC_SEQ_CST
<span class="lineNum">      61 </span>            :         #define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), (delta), __ATOMIC_SEQ_CST)
<span class="lineNum">      62 </span>            :     #else
<span class="lineNum">      63 </span>            :         #define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), (delta), 5)
<span class="lineNum">      64 </span>            :     #endif
<span class="lineNum">      65 </span>            :   #elif __GNUC__*10 + __GNUC_MINOR__ &gt;= 42
<span class="lineNum">      66 </span>            : 
<span class="lineNum">      67 </span>            :     #if !(defined WIN32 || defined _WIN32) &amp;&amp; (defined __i486__ || defined __i586__ || \
<span class="lineNum">      68 </span>            :         defined __i686__ || defined __MMX__ || defined __SSE__  || defined __ppc__) || \
<span class="lineNum">      69 </span>            :         (defined __GNUC__ &amp;&amp; defined _STLPORT_MAJOR) || \
<span class="lineNum">      70 </span>            :         defined __EMSCRIPTEN__
<span class="lineNum">      71 </span>            : 
<span class="lineNum">      72 </span>            :       #define CV_XADD __sync_fetch_and_add
<span class="lineNum">      73 </span>            :     #else
<span class="lineNum">      74 </span>            :       #include &lt;ext/atomicity.h&gt;
<span class="lineNum">      75 </span>            :       #define CV_XADD __gnu_cxx::__exchange_and_add
<span class="lineNum">      76 </span>            :     #endif
<span class="lineNum">      77 </span>            : 
<span class="lineNum">      78 </span>            :   #else
<span class="lineNum">      79 </span>            :     #include &lt;bits/atomicity.h&gt;
<span class="lineNum">      80 </span>            :     #if __GNUC__*10 + __GNUC_MINOR__ &gt;= 34
<span class="lineNum">      81 </span>            :       #define CV_XADD __gnu_cxx::__exchange_and_add
<span class="lineNum">      82 </span>            :     #else
<span class="lineNum">      83 </span>            :       #define CV_XADD __exchange_and_add
<span class="lineNum">      84 </span>            :     #endif
<span class="lineNum">      85 </span>            :   #endif
<span class="lineNum">      86 </span>            : 
<span class="lineNum">      87 </span>            : #elif defined WIN32 || defined _WIN32 || defined WINCE
<span class="lineNum">      88 </span>            :   namespace cv { CV_EXPORTS int _interlockedExchangeAdd(int* addr, int delta); }
<span class="lineNum">      89 </span>            :   #define CV_XADD cv::_interlockedExchangeAdd
<span class="lineNum">      90 </span>            : 
<span class="lineNum">      91 </span>            : #else
<span class="lineNum">      92 </span>            :   static inline int CV_XADD(int* addr, int delta)
<span class="lineNum">      93 </span>            :   { int tmp = *addr; *addr += delta; return tmp; }
<span class="lineNum">      94 </span>            : #endif
<span class="lineNum">      95 </span>            : 
<span class="lineNum">      96 </span>            : #include &lt;limits&gt;
<span class="lineNum">      97 </span>            : 
<span class="lineNum">      98 </span>            : #ifdef _MSC_VER
<span class="lineNum">      99 </span>            : # pragma warning(push)
<span class="lineNum">     100 </span>            : # pragma warning(disable:4127) //conditional expression is constant
<span class="lineNum">     101 </span>            : #endif
<span class="lineNum">     102 </span>            : 
<span class="lineNum">     103 </span>            : namespace cv
<span class="lineNum">     104 </span>            : {
<span class="lineNum">     105 </span>            : 
<span class="lineNum">     106 </span>            : using std::cos;
<span class="lineNum">     107 </span>            : using std::sin;
<span class="lineNum">     108 </span>            : using std::max;
<span class="lineNum">     109 </span>            : using std::min;
<span class="lineNum">     110 </span>            : using std::exp;
<span class="lineNum">     111 </span>            : using std::log;
<span class="lineNum">     112 </span>            : using std::pow;
<span class="lineNum">     113 </span>            : using std::sqrt;
<span class="lineNum">     114 </span>            : 
<span class="lineNum">     115 </span>            : 
<span class="lineNum">     116 </span>            : /////////////// saturate_cast (used in image &amp; signal processing) ///////////////////
<span class="lineNum">     117 </span>            : 
<span class="lineNum">     118 </span>            : template&lt;typename _Tp&gt; static inline _Tp saturate_cast(uchar v) { return _Tp(v); }
<span class="lineNum">     119 </span>            : template&lt;typename _Tp&gt; static inline _Tp saturate_cast(schar v) { return _Tp(v); }
<span class="lineNum">     120 </span>            : template&lt;typename _Tp&gt; static inline _Tp saturate_cast(ushort v) { return _Tp(v); }
<span class="lineNum">     121 </span>            : template&lt;typename _Tp&gt; static inline _Tp saturate_cast(short v) { return _Tp(v); }
<span class="lineNum">     122 </span>            : template&lt;typename _Tp&gt; static inline _Tp saturate_cast(unsigned v) { return _Tp(v); }
<span class="lineNum">     123 </span>            : template&lt;typename _Tp&gt; static inline _Tp saturate_cast(int v) { return _Tp(v); }
<span class="lineNum">     124 </span>            : template&lt;typename _Tp&gt; static inline _Tp saturate_cast(float v) { return _Tp(v); }
<span class="lineNum">     125 </span>            : template&lt;typename _Tp&gt; static inline _Tp saturate_cast(double v) { return _Tp(v); }
<span class="lineNum">     126 </span>            : 
<span class="lineNum">     127 </span>            : template&lt;&gt; inline uchar saturate_cast&lt;uchar&gt;(schar v)
<span class="lineNum">     128 </span>            : { return (uchar)std::max((int)v, 0); }
<span class="lineNum">     129 </span>            : template&lt;&gt; inline uchar saturate_cast&lt;uchar&gt;(ushort v)
<span class="lineNum">     130 </span>            : { return (uchar)std::min((unsigned)v, (unsigned)UCHAR_MAX); }
<span class="lineNum">     131 </span>            : template&lt;&gt; inline uchar saturate_cast&lt;uchar&gt;(int v)
<span class="lineNum">     132 </span>            : { return (uchar)((unsigned)v &lt;= UCHAR_MAX ? v : v &gt; 0 ? UCHAR_MAX : 0); }
<span class="lineNum">     133 </span>            : template&lt;&gt; inline uchar saturate_cast&lt;uchar&gt;(short v)
<span class="lineNum">     134 </span>            : { return saturate_cast&lt;uchar&gt;((int)v); }
<span class="lineNum">     135 </span>            : template&lt;&gt; inline uchar saturate_cast&lt;uchar&gt;(unsigned v)
<span class="lineNum">     136 </span>            : { return (uchar)std::min(v, (unsigned)UCHAR_MAX); }
<span class="lineNum">     137 </span>            : template&lt;&gt; inline uchar saturate_cast&lt;uchar&gt;(float v)
<span class="lineNum">     138 </span>            : { int iv = cvRound(v); return saturate_cast&lt;uchar&gt;(iv); }
<span class="lineNum">     139 </span>            : template&lt;&gt; inline uchar saturate_cast&lt;uchar&gt;(double v)
<span class="lineNum">     140 </span>            : { int iv = cvRound(v); return saturate_cast&lt;uchar&gt;(iv); }
<span class="lineNum">     141 </span>            : 
<span class="lineNum">     142 </span>            : template&lt;&gt; inline schar saturate_cast&lt;schar&gt;(uchar v)
<span class="lineNum">     143 </span>            : { return (schar)std::min((int)v, SCHAR_MAX); }
<span class="lineNum">     144 </span>            : template&lt;&gt; inline schar saturate_cast&lt;schar&gt;(ushort v)
<span class="lineNum">     145 </span>            : { return (schar)std::min((unsigned)v, (unsigned)SCHAR_MAX); }
<span class="lineNum">     146 </span>            : template&lt;&gt; inline schar saturate_cast&lt;schar&gt;(int v)
<span class="lineNum">     147 </span>            : {
<span class="lineNum">     148 </span>            :     return (schar)((unsigned)(v-SCHAR_MIN) &lt;= (unsigned)UCHAR_MAX ?
<span class="lineNum">     149 </span>            :                 v : v &gt; 0 ? SCHAR_MAX : SCHAR_MIN);
<span class="lineNum">     150 </span>            : }
<span class="lineNum">     151 </span>            : template&lt;&gt; inline schar saturate_cast&lt;schar&gt;(short v)
<span class="lineNum">     152 </span>            : { return saturate_cast&lt;schar&gt;((int)v); }
<span class="lineNum">     153 </span>            : template&lt;&gt; inline schar saturate_cast&lt;schar&gt;(unsigned v)
<span class="lineNum">     154 </span>            : { return (schar)std::min(v, (unsigned)SCHAR_MAX); }
<span class="lineNum">     155 </span>            : 
<span class="lineNum">     156 </span>            : template&lt;&gt; inline schar saturate_cast&lt;schar&gt;(float v)
<span class="lineNum">     157 </span>            : { int iv = cvRound(v); return saturate_cast&lt;schar&gt;(iv); }
<span class="lineNum">     158 </span>            : template&lt;&gt; inline schar saturate_cast&lt;schar&gt;(double v)
<span class="lineNum">     159 </span>            : { int iv = cvRound(v); return saturate_cast&lt;schar&gt;(iv); }
<span class="lineNum">     160 </span>            : 
<span class="lineNum">     161 </span>            : template&lt;&gt; inline ushort saturate_cast&lt;ushort&gt;(schar v)
<span class="lineNum">     162 </span>            : { return (ushort)std::max((int)v, 0); }
<span class="lineNum">     163 </span>            : template&lt;&gt; inline ushort saturate_cast&lt;ushort&gt;(short v)
<span class="lineNum">     164 </span>            : { return (ushort)std::max((int)v, 0); }
<span class="lineNum">     165 </span>            : template&lt;&gt; inline ushort saturate_cast&lt;ushort&gt;(int v)
<span class="lineNum">     166 </span>            : { return (ushort)((unsigned)v &lt;= (unsigned)USHRT_MAX ? v : v &gt; 0 ? USHRT_MAX : 0); }
<span class="lineNum">     167 </span>            : template&lt;&gt; inline ushort saturate_cast&lt;ushort&gt;(unsigned v)
<span class="lineNum">     168 </span>            : { return (ushort)std::min(v, (unsigned)USHRT_MAX); }
<span class="lineNum">     169 </span>            : template&lt;&gt; inline ushort saturate_cast&lt;ushort&gt;(float v)
<span class="lineNum">     170 </span>            : { int iv = cvRound(v); return saturate_cast&lt;ushort&gt;(iv); }
<span class="lineNum">     171 </span>            : template&lt;&gt; inline ushort saturate_cast&lt;ushort&gt;(double v)
<span class="lineNum">     172 </span>            : { int iv = cvRound(v); return saturate_cast&lt;ushort&gt;(iv); }
<span class="lineNum">     173 </span>            : 
<span class="lineNum">     174 </span>            : template&lt;&gt; inline short saturate_cast&lt;short&gt;(ushort v)
<span class="lineNum">     175 </span>            : { return (short)std::min((int)v, SHRT_MAX); }
<span class="lineNum">     176 </span>            : template&lt;&gt; inline short saturate_cast&lt;short&gt;(int v)
<span class="lineNum">     177 </span>            : {
<span class="lineNum">     178 </span>            :     return (short)((unsigned)(v - SHRT_MIN) &lt;= (unsigned)USHRT_MAX ?
<span class="lineNum">     179 </span>            :             v : v &gt; 0 ? SHRT_MAX : SHRT_MIN);
<span class="lineNum">     180 </span>            : }
<span class="lineNum">     181 </span>            : template&lt;&gt; inline short saturate_cast&lt;short&gt;(unsigned v)
<span class="lineNum">     182 </span>            : { return (short)std::min(v, (unsigned)SHRT_MAX); }
<span class="lineNum">     183 </span>            : template&lt;&gt; inline short saturate_cast&lt;short&gt;(float v)
<span class="lineNum">     184 </span>            : { int iv = cvRound(v); return saturate_cast&lt;short&gt;(iv); }
<span class="lineNum">     185 </span>            : template&lt;&gt; inline short saturate_cast&lt;short&gt;(double v)
<span class="lineNum">     186 </span>            : { int iv = cvRound(v); return saturate_cast&lt;short&gt;(iv); }
<span class="lineNum">     187 </span>            : 
<span class="lineNum">     188 </span>            : template&lt;&gt; inline int saturate_cast&lt;int&gt;(float v) { return cvRound(v); }
<span class="lineNum">     189 </span>            : template&lt;&gt; inline int saturate_cast&lt;int&gt;(double v) { return cvRound(v); }
<span class="lineNum">     190 </span>            : 
<span class="lineNum">     191 </span>            : // we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc.
<span class="lineNum">     192 </span>            : template&lt;&gt; inline unsigned saturate_cast&lt;unsigned&gt;(float v){ return cvRound(v); }
<span class="lineNum">     193 </span>            : template&lt;&gt; inline unsigned saturate_cast&lt;unsigned&gt;(double v) { return cvRound(v); }
<span class="lineNum">     194 </span>            : 
<span class="lineNum">     195 </span>            : inline int fast_abs(uchar v) { return v; }
<span class="lineNum">     196 </span>            : inline int fast_abs(schar v) { return std::abs((int)v); }
<span class="lineNum">     197 </span>            : inline int fast_abs(ushort v) { return v; }
<span class="lineNum">     198 </span>            : inline int fast_abs(short v) { return std::abs((int)v); }
<span class="lineNum">     199 </span>            : inline int fast_abs(int v) { return std::abs(v); }
<span class="lineNum">     200 </span>            : inline float fast_abs(float v) { return std::abs(v); }
<span class="lineNum">     201 </span>            : inline double fast_abs(double v) { return std::abs(v); }
<span class="lineNum">     202 </span>            : 
<span class="lineNum">     203 </span>            : //////////////////////////////// Matx /////////////////////////////////
<span class="lineNum">     204 </span>            : 
<span class="lineNum">     205 </span>            : 
<span class="lineNum">     206 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx()
<span class="lineNum">     207 </span>            : {
<span class="lineNum">     208 </span>            :     for(int i = 0; i &lt; channels; i++) val[i] = _Tp(0);
<span class="lineNum">     209 </span>            : }
<span class="lineNum">     210 </span>            : 
<span class="lineNum">     211 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx(_Tp v0)
<span class="lineNum">     212 </span>            : {
<span class="lineNum">     213 </span>            :     val[0] = v0;
<span class="lineNum">     214 </span>            :     for(int i = 1; i &lt; channels; i++) val[i] = _Tp(0);
<span class="lineNum">     215 </span>            : }
<span class="lineNum">     216 </span>            : 
<span class="lineNum">     217 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx(_Tp v0, _Tp v1)
<span class="lineNum">     218 </span>            : {
<span class="lineNum">     219 </span>            :     assert(channels &gt;= 2);
<span class="lineNum">     220 </span>            :     val[0] = v0; val[1] = v1;
<span class="lineNum">     221 </span>            :     for(int i = 2; i &lt; channels; i++) val[i] = _Tp(0);
<span class="lineNum">     222 </span>            : }
<span class="lineNum">     223 </span>            : 
<span class="lineNum">     224 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx(_Tp v0, _Tp v1, _Tp v2)
<span class="lineNum">     225 </span>            : {
<span class="lineNum">     226 </span>            :     assert(channels &gt;= 3);
<span class="lineNum">     227 </span>            :     val[0] = v0; val[1] = v1; val[2] = v2;
<span class="lineNum">     228 </span>            :     for(int i = 3; i &lt; channels; i++) val[i] = _Tp(0);
<span class="lineNum">     229 </span>            : }
<span class="lineNum">     230 </span>            : 
<span class="lineNum">     231 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3)
<span class="lineNum">     232 </span>            : {
<span class="lineNum">     233 </span>            :     assert(channels &gt;= 4);
<span class="lineNum">     234 </span>            :     val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
<span class="lineNum">     235 </span>            :     for(int i = 4; i &lt; channels; i++) val[i] = _Tp(0);
<span class="lineNum">     236 </span>            : }
<span class="lineNum">     237 </span>            : 
<span class="lineNum">     238 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4)
<span class="lineNum">     239 </span>            : {
<span class="lineNum">     240 </span>            :     assert(channels &gt;= 5);
<span class="lineNum">     241 </span>            :     val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; val[4] = v4;
<span class="lineNum">     242 </span>            :     for(int i = 5; i &lt; channels; i++) val[i] = _Tp(0);
<span class="lineNum">     243 </span>            : }
<span class="lineNum">     244 </span>            : 
<span class="lineNum">     245 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
<span class="lineNum">     246 </span>            :                                                         _Tp v4, _Tp v5)
<span class="lineNum">     247 </span>            : {
<span class="lineNum">     248 </span>            :     assert(channels &gt;= 6);
<span class="lineNum">     249 </span>            :     val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
<span class="lineNum">     250 </span>            :     val[4] = v4; val[5] = v5;
<span class="lineNum">     251 </span>            :     for(int i = 6; i &lt; channels; i++) val[i] = _Tp(0);
<span class="lineNum">     252 </span>            : }
<span class="lineNum">     253 </span>            : 
<span class="lineNum">     254 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
<span class="lineNum">     255 </span>            :                                                         _Tp v4, _Tp v5, _Tp v6)
<span class="lineNum">     256 </span>            : {
<span class="lineNum">     257 </span>            :     assert(channels &gt;= 7);
<span class="lineNum">     258 </span>            :     val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
<span class="lineNum">     259 </span>            :     val[4] = v4; val[5] = v5; val[6] = v6;
<span class="lineNum">     260 </span>            :     for(int i = 7; i &lt; channels; i++) val[i] = _Tp(0);
<span class="lineNum">     261 </span>            : }
<span class="lineNum">     262 </span>            : 
<span class="lineNum">     263 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
<span class="lineNum">     264 </span>            :                                                         _Tp v4, _Tp v5, _Tp v6, _Tp v7)
<span class="lineNum">     265 </span>            : {
<span class="lineNum">     266 </span>            :     assert(channels &gt;= 8);
<span class="lineNum">     267 </span>            :     val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
<span class="lineNum">     268 </span>            :     val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7;
<span class="lineNum">     269 </span>            :     for(int i = 8; i &lt; channels; i++) val[i] = _Tp(0);
<span class="lineNum">     270 </span>            : }
<span class="lineNum">     271 </span>            : 
<span class="lineNum">     272 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
<span class="lineNum">     273 </span>            :                                                         _Tp v4, _Tp v5, _Tp v6, _Tp v7,
<span class="lineNum">     274 </span>            :                                                         _Tp v8)
<span class="lineNum">     275 </span>            : {
<span class="lineNum">     276 </span>            :     assert(channels &gt;= 9);
<span class="lineNum">     277 </span>            :     val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
<span class="lineNum">     278 </span>            :     val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7;
<span class="lineNum">     279 </span>            :     val[8] = v8;
<span class="lineNum">     280 </span>            :     for(int i = 9; i &lt; channels; i++) val[i] = _Tp(0);
<span class="lineNum">     281 </span>            : }
<span class="lineNum">     282 </span>            : 
<span class="lineNum">     283 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
<span class="lineNum">     284 </span>            :                                                         _Tp v4, _Tp v5, _Tp v6, _Tp v7,
<span class="lineNum">     285 </span>            :                                                         _Tp v8, _Tp v9)
<span class="lineNum">     286 </span>            : {
<span class="lineNum">     287 </span>            :     assert(channels &gt;= 10);
<span class="lineNum">     288 </span>            :     val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
<span class="lineNum">     289 </span>            :     val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7;
<span class="lineNum">     290 </span>            :     val[8] = v8; val[9] = v9;
<span class="lineNum">     291 </span>            :     for(int i = 10; i &lt; channels; i++) val[i] = _Tp(0);
<span class="lineNum">     292 </span>            : }
<span class="lineNum">     293 </span>            : 
<span class="lineNum">     294 </span>            : 
<span class="lineNum">     295 </span>            : template&lt;typename _Tp, int m, int n&gt;
<span class="lineNum">     296 </span>            : inline Matx&lt;_Tp,m,n&gt;::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
<span class="lineNum">     297 </span>            :                             _Tp v4, _Tp v5, _Tp v6, _Tp v7,
<span class="lineNum">     298 </span>            :                             _Tp v8, _Tp v9, _Tp v10, _Tp v11)
<span class="lineNum">     299 </span>            : {
<span class="lineNum">     300 </span>            :     assert(channels == 12);
<span class="lineNum">     301 </span>            :     val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
<span class="lineNum">     302 </span>            :     val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7;
<span class="lineNum">     303 </span>            :     val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11;
<span class="lineNum">     304 </span>            : }
<span class="lineNum">     305 </span>            : 
<span class="lineNum">     306 </span>            : template&lt;typename _Tp, int m, int n&gt;
<span class="lineNum">     307 </span>            : inline Matx&lt;_Tp,m,n&gt;::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
<span class="lineNum">     308 </span>            :                            _Tp v4, _Tp v5, _Tp v6, _Tp v7,
<span class="lineNum">     309 </span>            :                            _Tp v8, _Tp v9, _Tp v10, _Tp v11,
<span class="lineNum">     310 </span>            :                            _Tp v12, _Tp v13, _Tp v14, _Tp v15)
<span class="lineNum">     311 </span>            : {
<span class="lineNum">     312 </span>            :     assert(channels == 16);
<span class="lineNum">     313 </span>            :     val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
<span class="lineNum">     314 </span>            :     val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7;
<span class="lineNum">     315 </span>            :     val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11;
<span class="lineNum">     316 </span>            :     val[12] = v12; val[13] = v13; val[14] = v14; val[15] = v15;
<span class="lineNum">     317 </span>            : }
<span class="lineNum">     318 </span>            : 
<span class="lineNum">     319 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt;::Matx(const _Tp* values)
<span class="lineNum">     320 </span>            : {
<span class="lineNum">     321 </span>            :     for( int i = 0; i &lt; channels; i++ ) val[i] = values[i];
<span class="lineNum">     322 </span>            : }
<span class="lineNum">     323 </span>            : 
<span class="lineNum">     324 </span>            : template&lt;typename _Tp, int m, int n&gt; inline Matx&lt;_Tp, m, n&gt; Matx&lt;_Tp, m, n&gt;::all(_Tp alpha)
<span class="lineNum">     325 </span>            : {
<span class="lineNum">     326 </span>            :     Matx&lt;_Tp, m, n&gt; M;
<span class="lineNum">     327 </span>            :     for( int i = 0; i &lt; m*n; i++ ) M.val[i] = alpha;
<span class="lineNum">     328 </span>            :     return M;
<span class="lineNum">     329 </span>            : }
<span class="lineNum">     330 </span>            : 
<span class="lineNum">     331 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     332 </span>            : Matx&lt;_Tp,m,n&gt; Matx&lt;_Tp,m,n&gt;::zeros()
<span class="lineNum">     333 </span>            : {
<span class="lineNum">     334 </span>            :     return all(0);
<span class="lineNum">     335 </span>            : }
<span class="lineNum">     336 </span>            : 
<span class="lineNum">     337 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     338 </span>            : Matx&lt;_Tp,m,n&gt; Matx&lt;_Tp,m,n&gt;::ones()
<span class="lineNum">     339 </span>            : {
<span class="lineNum">     340 </span>            :     return all(1);
<span class="lineNum">     341 </span>            : }
<span class="lineNum">     342 </span>            : 
<span class="lineNum">     343 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     344 </span>            : Matx&lt;_Tp,m,n&gt; Matx&lt;_Tp,m,n&gt;::eye()
<span class="lineNum">     345 </span>            : {
<span class="lineNum">     346 </span>            :     Matx&lt;_Tp,m,n&gt; M;
<span class="lineNum">     347 </span>            :     for(int i = 0; i &lt; MIN(m,n); i++)
<span class="lineNum">     348 </span>            :         M(i,i) = 1;
<span class="lineNum">     349 </span>            :     return M;
<span class="lineNum">     350 </span>            : }
<span class="lineNum">     351 </span>            : 
<span class="lineNum">     352 </span>            : template&lt;typename _Tp, int m, int n&gt; inline _Tp Matx&lt;_Tp, m, n&gt;::dot(const Matx&lt;_Tp, m, n&gt;&amp; M) const
<span class="lineNum">     353 </span>            : {
<span class="lineNum">     354 </span>            :     _Tp s = 0;
<span class="lineNum">     355 </span>            :     for( int i = 0; i &lt; m*n; i++ ) s += val[i]*M.val[i];
<span class="lineNum">     356 </span>            :     return s;
<span class="lineNum">     357 </span>            : }
<span class="lineNum">     358 </span>            : 
<span class="lineNum">     359 </span>            : 
<span class="lineNum">     360 </span>            : template&lt;typename _Tp, int m, int n&gt; inline double Matx&lt;_Tp, m, n&gt;::ddot(const Matx&lt;_Tp, m, n&gt;&amp; M) const
<span class="lineNum">     361 </span>            : {
<span class="lineNum">     362 </span>            :     double s = 0;
<span class="lineNum">     363 </span>            :     for( int i = 0; i &lt; m*n; i++ ) s += (double)val[i]*M.val[i];
<span class="lineNum">     364 </span>            :     return s;
<span class="lineNum">     365 </span>            : }
<span class="lineNum">     366 </span>            : 
<span class="lineNum">     367 </span>            : 
<span class="lineNum">     368 </span>            : 
<span class="lineNum">     369 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     370 </span>            : Matx&lt;_Tp,m,n&gt; Matx&lt;_Tp,m,n&gt;::diag(const typename Matx&lt;_Tp,m,n&gt;::diag_type&amp; d)
<span class="lineNum">     371 </span>            : {
<span class="lineNum">     372 </span>            :     Matx&lt;_Tp,m,n&gt; M;
<span class="lineNum">     373 </span>            :     for(int i = 0; i &lt; MIN(m,n); i++)
<span class="lineNum">     374 </span>            :         M(i,i) = d(i, 0);
<span class="lineNum">     375 </span>            :     return M;
<span class="lineNum">     376 </span>            : }
<span class="lineNum">     377 </span>            : 
<span class="lineNum">     378 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     379 </span>            : Matx&lt;_Tp,m,n&gt; Matx&lt;_Tp,m,n&gt;::randu(_Tp a, _Tp b)
<span class="lineNum">     380 </span>            : {
<span class="lineNum">     381 </span>            :     Matx&lt;_Tp,m,n&gt; M;
<span class="lineNum">     382 </span>            :     Mat matM(M, false);
<span class="lineNum">     383 </span>            :     cv::randu(matM, Scalar(a), Scalar(b));
<span class="lineNum">     384 </span>            :     return M;
<span class="lineNum">     385 </span>            : }
<span class="lineNum">     386 </span>            : 
<span class="lineNum">     387 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     388 </span>            : Matx&lt;_Tp,m,n&gt; Matx&lt;_Tp,m,n&gt;::randn(_Tp a, _Tp b)
<span class="lineNum">     389 </span>            : {
<span class="lineNum">     390 </span>            :     Matx&lt;_Tp,m,n&gt; M;
<span class="lineNum">     391 </span>            :     Mat matM(M, false);
<span class="lineNum">     392 </span>            :     cv::randn(matM, Scalar(a), Scalar(b));
<span class="lineNum">     393 </span>            :     return M;
<span class="lineNum">     394 </span>            : }
<span class="lineNum">     395 </span>            : 
<span class="lineNum">     396 </span>            : template&lt;typename _Tp, int m, int n&gt; template&lt;typename T2&gt;
<span class="lineNum">     397 </span>            : inline Matx&lt;_Tp, m, n&gt;::operator Matx&lt;T2, m, n&gt;() const
<span class="lineNum">     398 </span>            : {
<span class="lineNum">     399 </span>            :     Matx&lt;T2, m, n&gt; M;
<span class="lineNum">     400 </span>            :     for( int i = 0; i &lt; m*n; i++ ) M.val[i] = saturate_cast&lt;T2&gt;(val[i]);
<span class="lineNum">     401 </span>            :     return M;
<span class="lineNum">     402 </span>            : }
<span class="lineNum">     403 </span>            : 
<span class="lineNum">     404 </span>            : 
<span class="lineNum">     405 </span>            : template&lt;typename _Tp, int m, int n&gt; template&lt;int m1, int n1&gt; inline
<span class="lineNum">     406 </span>            : Matx&lt;_Tp, m1, n1&gt; Matx&lt;_Tp, m, n&gt;::reshape() const
<span class="lineNum">     407 </span>            : {
<span class="lineNum">     408 </span>            :     CV_DbgAssert(m1*n1 == m*n);
<span class="lineNum">     409 </span>            :     return (const Matx&lt;_Tp, m1, n1&gt;&amp;)*this;
<span class="lineNum">     410 </span>            : }
<span class="lineNum">     411 </span>            : 
<span class="lineNum">     412 </span>            : 
<span class="lineNum">     413 </span>            : template&lt;typename _Tp, int m, int n&gt;
<span class="lineNum">     414 </span>            : template&lt;int m1, int n1&gt; inline
<span class="lineNum">     415 </span>            : Matx&lt;_Tp, m1, n1&gt; Matx&lt;_Tp, m, n&gt;::get_minor(int i, int j) const
<span class="lineNum">     416 </span>            : {
<span class="lineNum">     417 </span>            :     CV_DbgAssert(0 &lt;= i &amp;&amp; i+m1 &lt;= m &amp;&amp; 0 &lt;= j &amp;&amp; j+n1 &lt;= n);
<span class="lineNum">     418 </span>            :     Matx&lt;_Tp, m1, n1&gt; s;
<span class="lineNum">     419 </span>            :     for( int di = 0; di &lt; m1; di++ )
<span class="lineNum">     420 </span>            :         for( int dj = 0; dj &lt; n1; dj++ )
<span class="lineNum">     421 </span>            :             s(di, dj) = (*this)(i+di, j+dj);
<span class="lineNum">     422 </span>            :     return s;
<span class="lineNum">     423 </span>            : }
<span class="lineNum">     424 </span>            : 
<span class="lineNum">     425 </span>            : 
<span class="lineNum">     426 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     427 </span>            : Matx&lt;_Tp, 1, n&gt; Matx&lt;_Tp, m, n&gt;::row(int i) const
<span class="lineNum">     428 </span>            : {
<span class="lineNum">     429 </span>            :     CV_DbgAssert((unsigned)i &lt; (unsigned)m);
<span class="lineNum">     430 </span>            :     return Matx&lt;_Tp, 1, n&gt;(&amp;val[i*n]);
<span class="lineNum">     431 </span>            : }
<span class="lineNum">     432 </span>            : 
<span class="lineNum">     433 </span>            : 
<span class="lineNum">     434 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     435 </span>            : Matx&lt;_Tp, m, 1&gt; Matx&lt;_Tp, m, n&gt;::col(int j) const
<span class="lineNum">     436 </span>            : {
<span class="lineNum">     437 </span>            :     CV_DbgAssert((unsigned)j &lt; (unsigned)n);
<span class="lineNum">     438 </span>            :     Matx&lt;_Tp, m, 1&gt; v;
<span class="lineNum">     439 </span>            :     for( int i = 0; i &lt; m; i++ )
<span class="lineNum">     440 </span>            :         v.val[i] = val[i*n + j];
<span class="lineNum">     441 </span>            :     return v;
<span class="lineNum">     442 </span>            : }
<span class="lineNum">     443 </span>            : 
<span class="lineNum">     444 </span>            : 
<span class="lineNum">     445 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     446 </span>            : typename Matx&lt;_Tp, m, n&gt;::diag_type Matx&lt;_Tp, m, n&gt;::diag() const
<span class="lineNum">     447 </span>            : {
<span class="lineNum">     448 </span>            :     diag_type d;
<span class="lineNum">     449 </span>            :     for( int i = 0; i &lt; MIN(m, n); i++ )
<span class="lineNum">     450 </span>            :         d.val[i] = val[i*n + i];
<span class="lineNum">     451 </span>            :     return d;
<span class="lineNum">     452 </span>            : }
<span class="lineNum">     453 </span>            : 
<span class="lineNum">     454 </span>            : 
<span class="lineNum">     455 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     456 </span>            : const _Tp&amp; Matx&lt;_Tp, m, n&gt;::operator ()(int i, int j) const
<span class="lineNum">     457 </span>            : {
<span class="lineNum">     458 </span>            :     CV_DbgAssert( (unsigned)i &lt; (unsigned)m &amp;&amp; (unsigned)j &lt; (unsigned)n );
<span class="lineNum">     459 </span>            :     return this-&gt;val[i*n + j];
<span class="lineNum">     460 </span>            : }
<span class="lineNum">     461 </span>            : 
<span class="lineNum">     462 </span>            : 
<span class="lineNum">     463 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     464 </span>            : _Tp&amp; Matx&lt;_Tp, m, n&gt;::operator ()(int i, int j)
<span class="lineNum">     465 </span>            : {
<span class="lineNum">     466 </span>            :     CV_DbgAssert( (unsigned)i &lt; (unsigned)m &amp;&amp; (unsigned)j &lt; (unsigned)n );
<span class="lineNum">     467 </span>            :     return val[i*n + j];
<span class="lineNum">     468 </span>            : }
<span class="lineNum">     469 </span>            : 
<span class="lineNum">     470 </span>            : 
<span class="lineNum">     471 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     472 </span>            : const _Tp&amp; Matx&lt;_Tp, m, n&gt;::operator ()(int i) const
<span class="lineNum">     473 </span>            : {
<span class="lineNum">     474 </span>            :     CV_DbgAssert( (m == 1 || n == 1) &amp;&amp; (unsigned)i &lt; (unsigned)(m+n-1) );
<span class="lineNum">     475 </span>            :     return val[i];
<span class="lineNum">     476 </span>            : }
<span class="lineNum">     477 </span>            : 
<span class="lineNum">     478 </span>            : 
<span class="lineNum">     479 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     480 </span>            : _Tp&amp; Matx&lt;_Tp, m, n&gt;::operator ()(int i)
<span class="lineNum">     481 </span>            : {
<span class="lineNum">     482 </span>            :     CV_DbgAssert( (m == 1 || n == 1) &amp;&amp; (unsigned)i &lt; (unsigned)(m+n-1) );
<span class="lineNum">     483 </span>            :     return val[i];
<span class="lineNum">     484 </span>            : }
<span class="lineNum">     485 </span>            : 
<span class="lineNum">     486 </span>            : 
<span class="lineNum">     487 </span>            : template&lt;typename _Tp1, typename _Tp2, int m, int n&gt; static inline
<span class="lineNum">     488 </span>            : Matx&lt;_Tp1, m, n&gt;&amp; operator += (Matx&lt;_Tp1, m, n&gt;&amp; a, const Matx&lt;_Tp2, m, n&gt;&amp; b)
<span class="lineNum">     489 </span>            : {
<span class="lineNum">     490 </span>            :     for( int i = 0; i &lt; m*n; i++ )
<span class="lineNum">     491 </span>            :         a.val[i] = saturate_cast&lt;_Tp1&gt;(a.val[i] + b.val[i]);
<span class="lineNum">     492 </span>            :     return a;
<span class="lineNum">     493 </span>            : }
<span class="lineNum">     494 </span>            : 
<span class="lineNum">     495 </span>            : 
<span class="lineNum">     496 </span>            : template&lt;typename _Tp1, typename _Tp2, int m, int n&gt; static inline
<span class="lineNum">     497 </span>            : Matx&lt;_Tp1, m, n&gt;&amp; operator -= (Matx&lt;_Tp1, m, n&gt;&amp; a, const Matx&lt;_Tp2, m, n&gt;&amp; b)
<span class="lineNum">     498 </span>            : {
<span class="lineNum">     499 </span>            :     for( int i = 0; i &lt; m*n; i++ )
<span class="lineNum">     500 </span>            :         a.val[i] = saturate_cast&lt;_Tp1&gt;(a.val[i] - b.val[i]);
<span class="lineNum">     501 </span>            :     return a;
<span class="lineNum">     502 </span>            : }
<span class="lineNum">     503 </span>            : 
<span class="lineNum">     504 </span>            : 
<span class="lineNum">     505 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     506 </span>            : Matx&lt;_Tp,m,n&gt;::Matx(const Matx&lt;_Tp, m, n&gt;&amp; a, const Matx&lt;_Tp, m, n&gt;&amp; b, Matx_AddOp)
<span class="lineNum">     507 </span>            : {
<span class="lineNum">     508 </span>            :     for( int i = 0; i &lt; m*n; i++ )
<span class="lineNum">     509 </span>            :         val[i] = saturate_cast&lt;_Tp&gt;(a.val[i] + b.val[i]);
<span class="lineNum">     510 </span>            : }
<span class="lineNum">     511 </span>            : 
<span class="lineNum">     512 </span>            : 
<span class="lineNum">     513 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     514 </span>            : Matx&lt;_Tp,m,n&gt;::Matx(const Matx&lt;_Tp, m, n&gt;&amp; a, const Matx&lt;_Tp, m, n&gt;&amp; b, Matx_SubOp)
<span class="lineNum">     515 </span>            : {
<span class="lineNum">     516 </span>            :     for( int i = 0; i &lt; m*n; i++ )
<span class="lineNum">     517 </span>            :         val[i] = saturate_cast&lt;_Tp&gt;(a.val[i] - b.val[i]);
<span class="lineNum">     518 </span>            : }
<span class="lineNum">     519 </span>            : 
<span class="lineNum">     520 </span>            : 
<span class="lineNum">     521 </span>            : template&lt;typename _Tp, int m, int n&gt; template&lt;typename _T2&gt; inline
<span class="lineNum">     522 </span>            : Matx&lt;_Tp,m,n&gt;::Matx(const Matx&lt;_Tp, m, n&gt;&amp; a, _T2 alpha, Matx_ScaleOp)
<span class="lineNum">     523 </span>            : {
<span class="lineNum">     524 </span>            :     for( int i = 0; i &lt; m*n; i++ )
<span class="lineNum">     525 </span>            :         val[i] = saturate_cast&lt;_Tp&gt;(a.val[i] * alpha);
<span class="lineNum">     526 </span>            : }
<span class="lineNum">     527 </span>            : 
<span class="lineNum">     528 </span>            : 
<span class="lineNum">     529 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     530 </span>            : Matx&lt;_Tp,m,n&gt;::Matx(const Matx&lt;_Tp, m, n&gt;&amp; a, const Matx&lt;_Tp, m, n&gt;&amp; b, Matx_MulOp)
<span class="lineNum">     531 </span>            : {
<span class="lineNum">     532 </span>            :     for( int i = 0; i &lt; m*n; i++ )
<span class="lineNum">     533 </span>            :         val[i] = saturate_cast&lt;_Tp&gt;(a.val[i] * b.val[i]);
<span class="lineNum">     534 </span>            : }
<span class="lineNum">     535 </span>            : 
<span class="lineNum">     536 </span>            : 
<span class="lineNum">     537 </span>            : template&lt;typename _Tp, int m, int n&gt; template&lt;int l&gt; inline
<span class="lineNum">     538 </span>            : Matx&lt;_Tp,m,n&gt;::Matx(const Matx&lt;_Tp, m, l&gt;&amp; a, const Matx&lt;_Tp, l, n&gt;&amp; b, Matx_MatMulOp)
<span class="lineNum">     539 </span>            : {
<span class="lineNum">     540 </span>            :     for( int i = 0; i &lt; m; i++ )
<span class="lineNum">     541 </span>            :         for( int j = 0; j &lt; n; j++ )
<span class="lineNum">     542 </span>            :         {
<span class="lineNum">     543 </span>            :             _Tp s = 0;
<span class="lineNum">     544 </span>            :             for( int k = 0; k &lt; l; k++ )
<span class="lineNum">     545 </span>            :                 s += a(i, k) * b(k, j);
<span class="lineNum">     546 </span>            :             val[i*n + j] = s;
<span class="lineNum">     547 </span>            :         }
<span class="lineNum">     548 </span>            : }
<span class="lineNum">     549 </span>            : 
<span class="lineNum">     550 </span>            : 
<span class="lineNum">     551 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     552 </span>            : Matx&lt;_Tp,m,n&gt;::Matx(const Matx&lt;_Tp, n, m&gt;&amp; a, Matx_TOp)
<span class="lineNum">     553 </span>            : {
<span class="lineNum">     554 </span>            :     for( int i = 0; i &lt; m; i++ )
<span class="lineNum">     555 </span>            :         for( int j = 0; j &lt; n; j++ )
<span class="lineNum">     556 </span>            :             val[i*n + j] = a(j, i);
<span class="lineNum">     557 </span>            : }
<span class="lineNum">     558 </span>            : 
<span class="lineNum">     559 </span>            : 
<span class="lineNum">     560 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     561 </span>            : Matx&lt;_Tp, m, n&gt; operator + (const Matx&lt;_Tp, m, n&gt;&amp; a, const Matx&lt;_Tp, m, n&gt;&amp; b)
<span class="lineNum">     562 </span>            : {
<span class="lineNum">     563 </span>            :     return Matx&lt;_Tp, m, n&gt;(a, b, Matx_AddOp());
<span class="lineNum">     564 </span>            : }
<span class="lineNum">     565 </span>            : 
<span class="lineNum">     566 </span>            : 
<span class="lineNum">     567 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     568 </span>            : Matx&lt;_Tp, m, n&gt; operator - (const Matx&lt;_Tp, m, n&gt;&amp; a, const Matx&lt;_Tp, m, n&gt;&amp; b)
<span class="lineNum">     569 </span>            : {
<span class="lineNum">     570 </span>            :     return Matx&lt;_Tp, m, n&gt;(a, b, Matx_SubOp());
<span class="lineNum">     571 </span>            : }
<span class="lineNum">     572 </span>            : 
<span class="lineNum">     573 </span>            : 
<span class="lineNum">     574 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     575 </span>            : Matx&lt;_Tp, m, n&gt;&amp; operator *= (Matx&lt;_Tp, m, n&gt;&amp; a, int alpha)
<span class="lineNum">     576 </span>            : {
<span class="lineNum">     577 </span>            :     for( int i = 0; i &lt; m*n; i++ )
<span class="lineNum">     578 </span>            :         a.val[i] = saturate_cast&lt;_Tp&gt;(a.val[i] * alpha);
<span class="lineNum">     579 </span>            :     return a;
<span class="lineNum">     580 </span>            : }
<span class="lineNum">     581 </span>            : 
<span class="lineNum">     582 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     583 </span>            : Matx&lt;_Tp, m, n&gt;&amp; operator *= (Matx&lt;_Tp, m, n&gt;&amp; a, float alpha)
<span class="lineNum">     584 </span>            : {
<span class="lineNum">     585 </span>            :     for( int i = 0; i &lt; m*n; i++ )
<span class="lineNum">     586 </span>            :         a.val[i] = saturate_cast&lt;_Tp&gt;(a.val[i] * alpha);
<span class="lineNum">     587 </span>            :     return a;
<span class="lineNum">     588 </span>            : }
<span class="lineNum">     589 </span>            : 
<span class="lineNum">     590 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     591 </span>            : Matx&lt;_Tp, m, n&gt;&amp; operator *= (Matx&lt;_Tp, m, n&gt;&amp; a, double alpha)
<span class="lineNum">     592 </span>            : {
<span class="lineNum">     593 </span>            :     for( int i = 0; i &lt; m*n; i++ )
<span class="lineNum">     594 </span>            :         a.val[i] = saturate_cast&lt;_Tp&gt;(a.val[i] * alpha);
<span class="lineNum">     595 </span>            :     return a;
<span class="lineNum">     596 </span>            : }
<span class="lineNum">     597 </span>            : 
<span class="lineNum">     598 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     599 </span>            : Matx&lt;_Tp, m, n&gt; operator * (const Matx&lt;_Tp, m, n&gt;&amp; a, int alpha)
<span class="lineNum">     600 </span>            : {
<span class="lineNum">     601 </span>            :     return Matx&lt;_Tp, m, n&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">     602 </span>            : }
<span class="lineNum">     603 </span>            : 
<span class="lineNum">     604 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     605 </span>            : Matx&lt;_Tp, m, n&gt; operator * (const Matx&lt;_Tp, m, n&gt;&amp; a, float alpha)
<span class="lineNum">     606 </span>            : {
<span class="lineNum">     607 </span>            :     return Matx&lt;_Tp, m, n&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">     608 </span>            : }
<span class="lineNum">     609 </span>            : 
<span class="lineNum">     610 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     611 </span>            : Matx&lt;_Tp, m, n&gt; operator * (const Matx&lt;_Tp, m, n&gt;&amp; a, double alpha)
<span class="lineNum">     612 </span>            : {
<span class="lineNum">     613 </span>            :     return Matx&lt;_Tp, m, n&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">     614 </span>            : }
<span class="lineNum">     615 </span>            : 
<span class="lineNum">     616 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     617 </span>            : Matx&lt;_Tp, m, n&gt; operator * (int alpha, const Matx&lt;_Tp, m, n&gt;&amp; a)
<span class="lineNum">     618 </span>            : {
<span class="lineNum">     619 </span>            :     return Matx&lt;_Tp, m, n&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">     620 </span>            : }
<span class="lineNum">     621 </span>            : 
<span class="lineNum">     622 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     623 </span>            : Matx&lt;_Tp, m, n&gt; operator * (float alpha, const Matx&lt;_Tp, m, n&gt;&amp; a)
<span class="lineNum">     624 </span>            : {
<span class="lineNum">     625 </span>            :     return Matx&lt;_Tp, m, n&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">     626 </span>            : }
<span class="lineNum">     627 </span>            : 
<span class="lineNum">     628 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     629 </span>            : Matx&lt;_Tp, m, n&gt; operator * (double alpha, const Matx&lt;_Tp, m, n&gt;&amp; a)
<span class="lineNum">     630 </span>            : {
<span class="lineNum">     631 </span>            :     return Matx&lt;_Tp, m, n&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">     632 </span>            : }
<span class="lineNum">     633 </span>            : 
<span class="lineNum">     634 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     635 </span>            : Matx&lt;_Tp, m, n&gt; operator - (const Matx&lt;_Tp, m, n&gt;&amp; a)
<span class="lineNum">     636 </span>            : {
<span class="lineNum">     637 </span>            :     return Matx&lt;_Tp, m, n&gt;(a, -1, Matx_ScaleOp());
<span class="lineNum">     638 </span>            : }
<span class="lineNum">     639 </span>            : 
<span class="lineNum">     640 </span>            : 
<span class="lineNum">     641 </span>            : template&lt;typename _Tp, int m, int n, int l&gt; static inline
<span class="lineNum">     642 </span>            : Matx&lt;_Tp, m, n&gt; operator * (const Matx&lt;_Tp, m, l&gt;&amp; a, const Matx&lt;_Tp, l, n&gt;&amp; b)
<span class="lineNum">     643 </span>            : {
<span class="lineNum">     644 </span>            :     return Matx&lt;_Tp, m, n&gt;(a, b, Matx_MatMulOp());
<span class="lineNum">     645 </span>            : }
<span class="lineNum">     646 </span>            : 
<span class="lineNum">     647 </span>            : 
<span class="lineNum">     648 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     649 </span>            : Vec&lt;_Tp, m&gt; operator * (const Matx&lt;_Tp, m, n&gt;&amp; a, const Vec&lt;_Tp, n&gt;&amp; b)
<span class="lineNum">     650 </span>            : {
<span class="lineNum">     651 </span>            :     Matx&lt;_Tp, m, 1&gt; c(a, b, Matx_MatMulOp());
<span class="lineNum">     652 </span>            :     return reinterpret_cast&lt;const Vec&lt;_Tp, m&gt;&amp;&gt;(c);
<span class="lineNum">     653 </span>            : }
<span class="lineNum">     654 </span>            : 
<span class="lineNum">     655 </span>            : 
<span class="lineNum">     656 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">     657 </span>            : Point_&lt;_Tp&gt; operator * (const Matx&lt;_Tp, 2, 2&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">     658 </span>            : {
<span class="lineNum">     659 </span>            :     Matx&lt;_Tp, 2, 1&gt; tmp = a*Vec&lt;_Tp,2&gt;(b.x, b.y);
<span class="lineNum">     660 </span>            :     return Point_&lt;_Tp&gt;(tmp.val[0], tmp.val[1]);
<span class="lineNum">     661 </span>            : }
<span class="lineNum">     662 </span>            : 
<span class="lineNum">     663 </span>            : 
<span class="lineNum">     664 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">     665 </span>            : Point3_&lt;_Tp&gt; operator * (const Matx&lt;_Tp, 3, 3&gt;&amp; a, const Point3_&lt;_Tp&gt;&amp; b)
<span class="lineNum">     666 </span>            : {
<span class="lineNum">     667 </span>            :     Matx&lt;_Tp, 3, 1&gt; tmp = a*Vec&lt;_Tp,3&gt;(b.x, b.y, b.z);
<span class="lineNum">     668 </span>            :     return Point3_&lt;_Tp&gt;(tmp.val[0], tmp.val[1], tmp.val[2]);
<span class="lineNum">     669 </span>            : }
<span class="lineNum">     670 </span>            : 
<span class="lineNum">     671 </span>            : 
<span class="lineNum">     672 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">     673 </span>            : Point3_&lt;_Tp&gt; operator * (const Matx&lt;_Tp, 3, 3&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">     674 </span>            : {
<span class="lineNum">     675 </span>            :     Matx&lt;_Tp, 3, 1&gt; tmp = a*Vec&lt;_Tp,3&gt;(b.x, b.y, 1);
<span class="lineNum">     676 </span>            :     return Point3_&lt;_Tp&gt;(tmp.val[0], tmp.val[1], tmp.val[2]);
<span class="lineNum">     677 </span>            : }
<span class="lineNum">     678 </span>            : 
<span class="lineNum">     679 </span>            : 
<span class="lineNum">     680 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">     681 </span>            : Matx&lt;_Tp, 4, 1&gt; operator * (const Matx&lt;_Tp, 4, 4&gt;&amp; a, const Point3_&lt;_Tp&gt;&amp; b)
<span class="lineNum">     682 </span>            : {
<span class="lineNum">     683 </span>            :     return a*Matx&lt;_Tp, 4, 1&gt;(b.x, b.y, b.z, 1);
<span class="lineNum">     684 </span>            : }
<span class="lineNum">     685 </span>            : 
<span class="lineNum">     686 </span>            : 
<span class="lineNum">     687 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">     688 </span>            : Scalar operator * (const Matx&lt;_Tp, 4, 4&gt;&amp; a, const Scalar&amp; b)
<span class="lineNum">     689 </span>            : {
<span class="lineNum">     690 </span>            :     Matx&lt;double, 4, 1&gt; c(Matx&lt;double, 4, 4&gt;(a), b, Matx_MatMulOp());
<span class="lineNum">     691 </span>            :     return static_cast&lt;const Scalar&amp;&gt;(c);
<span class="lineNum">     692 </span>            : }
<span class="lineNum">     693 </span>            : 
<span class="lineNum">     694 </span>            : 
<span class="lineNum">     695 </span>            : static inline
<span class="lineNum">     696 </span>            : Scalar operator * (const Matx&lt;double, 4, 4&gt;&amp; a, const Scalar&amp; b)
<span class="lineNum">     697 </span>            : {
<span class="lineNum">     698 </span>            :     Matx&lt;double, 4, 1&gt; c(a, b, Matx_MatMulOp());
<span class="lineNum">     699 </span>            :     return static_cast&lt;const Scalar&amp;&gt;(c);
<span class="lineNum">     700 </span>            : }
<span class="lineNum">     701 </span>            : 
<span class="lineNum">     702 </span>            : 
<span class="lineNum">     703 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     704 </span>            : Matx&lt;_Tp, m, n&gt; Matx&lt;_Tp, m, n&gt;::mul(const Matx&lt;_Tp, m, n&gt;&amp; a) const
<span class="lineNum">     705 </span>            : {
<span class="lineNum">     706 </span>            :     return Matx&lt;_Tp, m, n&gt;(*this, a, Matx_MulOp());
<span class="lineNum">     707 </span>            : }
<span class="lineNum">     708 </span>            : 
<span class="lineNum">     709 </span>            : 
<span class="lineNum">     710 </span>            : CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n);
<span class="lineNum">     711 </span>            : CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n);
<span class="lineNum">     712 </span>            : CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n);
<span class="lineNum">     713 </span>            : CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n);
<span class="lineNum">     714 </span>            : 
<span class="lineNum">     715 </span>            : 
<span class="lineNum">     716 </span>            : template&lt;typename _Tp, int m&gt; struct Matx_DetOp
<span class="lineNum">     717 </span>            : {
<span class="lineNum">     718 </span>            :     double operator ()(const Matx&lt;_Tp, m, m&gt;&amp; a) const
<span class="lineNum">     719 </span>            :     {
<span class="lineNum">     720 </span>            :         Matx&lt;_Tp, m, m&gt; temp = a;
<span class="lineNum">     721 </span>            :         double p = LU(temp.val, m*sizeof(_Tp), m, 0, 0, 0);
<span class="lineNum">     722 </span>            :         if( p == 0 )
<span class="lineNum">     723 </span>            :             return p;
<span class="lineNum">     724 </span>            :         for( int i = 0; i &lt; m; i++ )
<span class="lineNum">     725 </span>            :             p *= temp(i, i);
<span class="lineNum">     726 </span>            :         return 1./p;
<span class="lineNum">     727 </span>            :     }
<span class="lineNum">     728 </span>            : };
<span class="lineNum">     729 </span>            : 
<span class="lineNum">     730 </span>            : 
<span class="lineNum">     731 </span>            : template&lt;typename _Tp&gt; struct Matx_DetOp&lt;_Tp, 1&gt;
<span class="lineNum">     732 </span>            : {
<span class="lineNum">     733 </span>            :     double operator ()(const Matx&lt;_Tp, 1, 1&gt;&amp; a) const
<span class="lineNum">     734 </span>            :     {
<span class="lineNum">     735 </span>            :         return a(0,0);
<span class="lineNum">     736 </span>            :     }
<span class="lineNum">     737 </span>            : };
<span class="lineNum">     738 </span>            : 
<span class="lineNum">     739 </span>            : 
<span class="lineNum">     740 </span>            : template&lt;typename _Tp&gt; struct Matx_DetOp&lt;_Tp, 2&gt;
<span class="lineNum">     741 </span>            : {
<span class="lineNum">     742 </span>            :     double operator ()(const Matx&lt;_Tp, 2, 2&gt;&amp; a) const
<span class="lineNum">     743 </span>            :     {
<span class="lineNum">     744 </span>            :         return a(0,0)*a(1,1) - a(0,1)*a(1,0);
<span class="lineNum">     745 </span>            :     }
<span class="lineNum">     746 </span>            : };
<span class="lineNum">     747 </span>            : 
<span class="lineNum">     748 </span>            : 
<span class="lineNum">     749 </span>            : template&lt;typename _Tp&gt; struct Matx_DetOp&lt;_Tp, 3&gt;
<span class="lineNum">     750 </span>            : {
<span class="lineNum">     751 </span>            :     double operator ()(const Matx&lt;_Tp, 3, 3&gt;&amp; a) const
<span class="lineNum">     752 </span>            :     {
<span class="lineNum">     753 </span>            :         return a(0,0)*(a(1,1)*a(2,2) - a(2,1)*a(1,2)) -
<span class="lineNum">     754 </span>            :             a(0,1)*(a(1,0)*a(2,2) - a(2,0)*a(1,2)) +
<span class="lineNum">     755 </span>            :             a(0,2)*(a(1,0)*a(2,1) - a(2,0)*a(1,1));
<span class="lineNum">     756 </span>            :     }
<span class="lineNum">     757 </span>            : };
<span class="lineNum">     758 </span>            : 
<span class="lineNum">     759 </span>            : template&lt;typename _Tp, int m&gt; static inline
<span class="lineNum">     760 </span>            : double determinant(const Matx&lt;_Tp, m, m&gt;&amp; a)
<span class="lineNum">     761 </span>            : {
<span class="lineNum">     762 </span>            :     return Matx_DetOp&lt;_Tp, m&gt;()(a);
<span class="lineNum">     763 </span>            : }
<span class="lineNum">     764 </span>            : 
<span class="lineNum">     765 </span>            : 
<span class="lineNum">     766 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">     767 </span>            : double trace(const Matx&lt;_Tp, m, n&gt;&amp; a)
<span class="lineNum">     768 </span>            : {
<span class="lineNum">     769 </span>            :     _Tp s = 0;
<span class="lineNum">     770 </span>            :     for( int i = 0; i &lt; std::min(m, n); i++ )
<span class="lineNum">     771 </span>            :         s += a(i,i);
<span class="lineNum">     772 </span>            :     return s;
<span class="lineNum">     773 </span>            : }
<span class="lineNum">     774 </span>            : 
<span class="lineNum">     775 </span>            : 
<span class="lineNum">     776 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     777 </span>            : Matx&lt;_Tp, n, m&gt; Matx&lt;_Tp, m, n&gt;::t() const
<span class="lineNum">     778 </span>            : {
<span class="lineNum">     779 </span>            :     return Matx&lt;_Tp, n, m&gt;(*this, Matx_TOp());
<span class="lineNum">     780 </span>            : }
<span class="lineNum">     781 </span>            : 
<span class="lineNum">     782 </span>            : 
<span class="lineNum">     783 </span>            : template&lt;typename _Tp, int m&gt; struct Matx_FastInvOp
<span class="lineNum">     784 </span>            : {
<span class="lineNum">     785 </span>            :     bool operator()(const Matx&lt;_Tp, m, m&gt;&amp; a, Matx&lt;_Tp, m, m&gt;&amp; b, int method) const
<span class="lineNum">     786 </span>            :     {
<span class="lineNum">     787 </span>            :         Matx&lt;_Tp, m, m&gt; temp = a;
<span class="lineNum">     788 </span>            : 
<span class="lineNum">     789 </span>            :         // assume that b is all 0's on input =&gt; make it a unity matrix
<span class="lineNum">     790 </span>            :         for( int i = 0; i &lt; m; i++ )
<span class="lineNum">     791 </span>            :             b(i, i) = (_Tp)1;
<span class="lineNum">     792 </span>            : 
<span class="lineNum">     793 </span>            :         if( method == DECOMP_CHOLESKY )
<span class="lineNum">     794 </span>            :             return Cholesky(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m);
<span class="lineNum">     795 </span>            : 
<span class="lineNum">     796 </span>            :         return LU(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m) != 0;
<span class="lineNum">     797 </span>            :     }
<span class="lineNum">     798 </span>            : };
<span class="lineNum">     799 </span>            : 
<span class="lineNum">     800 </span>            : 
<span class="lineNum">     801 </span>            : template&lt;typename _Tp&gt; struct Matx_FastInvOp&lt;_Tp, 2&gt;
<span class="lineNum">     802 </span>            : {
<span class="lineNum">     803 </span>            :     bool operator()(const Matx&lt;_Tp, 2, 2&gt;&amp; a, Matx&lt;_Tp, 2, 2&gt;&amp; b, int) const
<span class="lineNum">     804 </span>            :     {
<span class="lineNum">     805 </span>            :         _Tp d = determinant(a);
<span class="lineNum">     806 </span>            :         if( d == 0 )
<span class="lineNum">     807 </span>            :             return false;
<span class="lineNum">     808 </span>            :         d = 1/d;
<span class="lineNum">     809 </span>            :         b(1,1) = a(0,0)*d;
<span class="lineNum">     810 </span>            :         b(0,0) = a(1,1)*d;
<span class="lineNum">     811 </span>            :         b(0,1) = -a(0,1)*d;
<span class="lineNum">     812 </span>            :         b(1,0) = -a(1,0)*d;
<span class="lineNum">     813 </span>            :         return true;
<span class="lineNum">     814 </span>            :     }
<span class="lineNum">     815 </span>            : };
<span class="lineNum">     816 </span>            : 
<span class="lineNum">     817 </span>            : 
<span class="lineNum">     818 </span>            : template&lt;typename _Tp&gt; struct Matx_FastInvOp&lt;_Tp, 3&gt;
<span class="lineNum">     819 </span>            : {
<span class="lineNum">     820 </span>            :     bool operator()(const Matx&lt;_Tp, 3, 3&gt;&amp; a, Matx&lt;_Tp, 3, 3&gt;&amp; b, int) const
<span class="lineNum">     821 </span>            :     {
<span class="lineNum">     822 </span>            :         _Tp d = (_Tp)determinant(a);
<span class="lineNum">     823 </span>            :         if( d == 0 )
<span class="lineNum">     824 </span>            :             return false;
<span class="lineNum">     825 </span>            :         d = 1/d;
<span class="lineNum">     826 </span>            :         b(0,0) = (a(1,1) * a(2,2) - a(1,2) * a(2,1)) * d;
<span class="lineNum">     827 </span>            :         b(0,1) = (a(0,2) * a(2,1) - a(0,1) * a(2,2)) * d;
<span class="lineNum">     828 </span>            :         b(0,2) = (a(0,1) * a(1,2) - a(0,2) * a(1,1)) * d;
<span class="lineNum">     829 </span>            : 
<span class="lineNum">     830 </span>            :         b(1,0) = (a(1,2) * a(2,0) - a(1,0) * a(2,2)) * d;
<span class="lineNum">     831 </span>            :         b(1,1) = (a(0,0) * a(2,2) - a(0,2) * a(2,0)) * d;
<span class="lineNum">     832 </span>            :         b(1,2) = (a(0,2) * a(1,0) - a(0,0) * a(1,2)) * d;
<span class="lineNum">     833 </span>            : 
<span class="lineNum">     834 </span>            :         b(2,0) = (a(1,0) * a(2,1) - a(1,1) * a(2,0)) * d;
<span class="lineNum">     835 </span>            :         b(2,1) = (a(0,1) * a(2,0) - a(0,0) * a(2,1)) * d;
<span class="lineNum">     836 </span>            :         b(2,2) = (a(0,0) * a(1,1) - a(0,1) * a(1,0)) * d;
<span class="lineNum">     837 </span>            :         return true;
<span class="lineNum">     838 </span>            :     }
<span class="lineNum">     839 </span>            : };
<span class="lineNum">     840 </span>            : 
<span class="lineNum">     841 </span>            : 
<span class="lineNum">     842 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     843 </span>            : Matx&lt;_Tp, n, m&gt; Matx&lt;_Tp, m, n&gt;::inv(int method) const
<span class="lineNum">     844 </span>            : {
<span class="lineNum">     845 </span>            :     Matx&lt;_Tp, n, m&gt; b;
<span class="lineNum">     846 </span>            :     bool ok;
<span class="lineNum">     847 </span>            :     if( method == DECOMP_LU || method == DECOMP_CHOLESKY )
<span class="lineNum">     848 </span>            :         ok = Matx_FastInvOp&lt;_Tp, m&gt;()(*this, b, method);
<span class="lineNum">     849 </span>            :     else
<span class="lineNum">     850 </span>            :     {
<span class="lineNum">     851 </span>            :         Mat A(*this, false), B(b, false);
<span class="lineNum">     852 </span>            :         ok = (invert(A, B, method) != 0);
<span class="lineNum">     853 </span>            :     }
<span class="lineNum">     854 </span>            :     return ok ? b : Matx&lt;_Tp, n, m&gt;::zeros();
<span class="lineNum">     855 </span>            : }
<span class="lineNum">     856 </span>            : 
<span class="lineNum">     857 </span>            : 
<span class="lineNum">     858 </span>            : template&lt;typename _Tp, int m, int n&gt; struct Matx_FastSolveOp
<span class="lineNum">     859 </span>            : {
<span class="lineNum">     860 </span>            :     bool operator()(const Matx&lt;_Tp, m, m&gt;&amp; a, const Matx&lt;_Tp, m, n&gt;&amp; b,
<span class="lineNum">     861 </span>            :                     Matx&lt;_Tp, m, n&gt;&amp; x, int method) const
<span class="lineNum">     862 </span>            :     {
<span class="lineNum">     863 </span>            :         Matx&lt;_Tp, m, m&gt; temp = a;
<span class="lineNum">     864 </span>            :         x = b;
<span class="lineNum">     865 </span>            :         if( method == DECOMP_CHOLESKY )
<span class="lineNum">     866 </span>            :             return Cholesky(temp.val, m*sizeof(_Tp), m, x.val, n*sizeof(_Tp), n);
<span class="lineNum">     867 </span>            : 
<span class="lineNum">     868 </span>            :         return LU(temp.val, m*sizeof(_Tp), m, x.val, n*sizeof(_Tp), n) != 0;
<span class="lineNum">     869 </span>            :     }
<span class="lineNum">     870 </span>            : };
<span class="lineNum">     871 </span>            : 
<span class="lineNum">     872 </span>            : 
<span class="lineNum">     873 </span>            : template&lt;typename _Tp&gt; struct Matx_FastSolveOp&lt;_Tp, 2, 1&gt;
<span class="lineNum">     874 </span>            : {
<span class="lineNum">     875 </span>            :     bool operator()(const Matx&lt;_Tp, 2, 2&gt;&amp; a, const Matx&lt;_Tp, 2, 1&gt;&amp; b,
<span class="lineNum">     876 </span>            :                     Matx&lt;_Tp, 2, 1&gt;&amp; x, int) const
<span class="lineNum">     877 </span>            :     {
<span class="lineNum">     878 </span>            :         _Tp d = determinant(a);
<span class="lineNum">     879 </span>            :         if( d == 0 )
<span class="lineNum">     880 </span>            :             return false;
<span class="lineNum">     881 </span>            :         d = 1/d;
<span class="lineNum">     882 </span>            :         x(0) = (b(0)*a(1,1) - b(1)*a(0,1))*d;
<span class="lineNum">     883 </span>            :         x(1) = (b(1)*a(0,0) - b(0)*a(1,0))*d;
<span class="lineNum">     884 </span>            :         return true;
<span class="lineNum">     885 </span>            :     }
<span class="lineNum">     886 </span>            : };
<span class="lineNum">     887 </span>            : 
<span class="lineNum">     888 </span>            : 
<span class="lineNum">     889 </span>            : template&lt;typename _Tp&gt; struct Matx_FastSolveOp&lt;_Tp, 3, 1&gt;
<span class="lineNum">     890 </span>            : {
<span class="lineNum">     891 </span>            :     bool operator()(const Matx&lt;_Tp, 3, 3&gt;&amp; a, const Matx&lt;_Tp, 3, 1&gt;&amp; b,
<span class="lineNum">     892 </span>            :                     Matx&lt;_Tp, 3, 1&gt;&amp; x, int) const
<span class="lineNum">     893 </span>            :     {
<span class="lineNum">     894 </span>            :         _Tp d = (_Tp)determinant(a);
<span class="lineNum">     895 </span>            :         if( d == 0 )
<span class="lineNum">     896 </span>            :             return false;
<span class="lineNum">     897 </span>            :         d = 1/d;
<span class="lineNum">     898 </span>            :         x(0) = d*(b(0)*(a(1,1)*a(2,2) - a(1,2)*a(2,1)) -
<span class="lineNum">     899 </span>            :                 a(0,1)*(b(1)*a(2,2) - a(1,2)*b(2)) +
<span class="lineNum">     900 </span>            :                 a(0,2)*(b(1)*a(2,1) - a(1,1)*b(2)));
<span class="lineNum">     901 </span>            : 
<span class="lineNum">     902 </span>            :         x(1) = d*(a(0,0)*(b(1)*a(2,2) - a(1,2)*b(2)) -
<span class="lineNum">     903 </span>            :                 b(0)*(a(1,0)*a(2,2) - a(1,2)*a(2,0)) +
<span class="lineNum">     904 </span>            :                 a(0,2)*(a(1,0)*b(2) - b(1)*a(2,0)));
<span class="lineNum">     905 </span>            : 
<span class="lineNum">     906 </span>            :         x(2) = d*(a(0,0)*(a(1,1)*b(2) - b(1)*a(2,1)) -
<span class="lineNum">     907 </span>            :                 a(0,1)*(a(1,0)*b(2) - b(1)*a(2,0)) +
<span class="lineNum">     908 </span>            :                 b(0)*(a(1,0)*a(2,1) - a(1,1)*a(2,0)));
<span class="lineNum">     909 </span>            :         return true;
<span class="lineNum">     910 </span>            :     }
<span class="lineNum">     911 </span>            : };
<span class="lineNum">     912 </span>            : 
<span class="lineNum">     913 </span>            : 
<span class="lineNum">     914 </span>            : template&lt;typename _Tp, int m, int n&gt; template&lt;int l&gt; inline
<span class="lineNum">     915 </span>            : Matx&lt;_Tp, n, l&gt; Matx&lt;_Tp, m, n&gt;::solve(const Matx&lt;_Tp, m, l&gt;&amp; rhs, int method) const
<span class="lineNum">     916 </span>            : {
<span class="lineNum">     917 </span>            :     Matx&lt;_Tp, n, l&gt; x;
<span class="lineNum">     918 </span>            :     bool ok;
<span class="lineNum">     919 </span>            :     if( method == DECOMP_LU || method == DECOMP_CHOLESKY )
<span class="lineNum">     920 </span>            :         ok = Matx_FastSolveOp&lt;_Tp, m, l&gt;()(*this, rhs, x, method);
<span class="lineNum">     921 </span>            :     else
<span class="lineNum">     922 </span>            :     {
<span class="lineNum">     923 </span>            :         Mat A(*this, false), B(rhs, false), X(x, false);
<span class="lineNum">     924 </span>            :         ok = cv::solve(A, B, X, method);
<span class="lineNum">     925 </span>            :     }
<span class="lineNum">     926 </span>            : 
<span class="lineNum">     927 </span>            :     return ok ? x : Matx&lt;_Tp, n, l&gt;::zeros();
<span class="lineNum">     928 </span>            : }
<span class="lineNum">     929 </span>            : 
<span class="lineNum">     930 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">     931 </span>            : Vec&lt;_Tp, n&gt; Matx&lt;_Tp, m, n&gt;::solve(const Vec&lt;_Tp, m&gt;&amp; rhs, int method) const
<span class="lineNum">     932 </span>            : {
<span class="lineNum">     933 </span>            :     Matx&lt;_Tp, n, 1&gt; x = solve(reinterpret_cast&lt;const Matx&lt;_Tp, m, 1&gt;&amp;&gt;(rhs), method);
<span class="lineNum">     934 </span>            :     return reinterpret_cast&lt;Vec&lt;_Tp, n&gt;&amp;&gt;(x);
<span class="lineNum">     935 </span>            : }
<span class="lineNum">     936 </span>            : 
<span class="lineNum">     937 </span>            : template&lt;typename _Tp, typename _AccTp&gt; static inline
<span class="lineNum">     938 </span>            : _AccTp normL2Sqr(const _Tp* a, int n)
<span class="lineNum">     939 </span>            : {
<span class="lineNum">     940 </span>            :     _AccTp s = 0;
<span class="lineNum">     941 </span>            :     int i=0;
<span class="lineNum">     942 </span>            :  #if CV_ENABLE_UNROLLED
<span class="lineNum">     943 </span>            :     for( ; i &lt;= n - 4; i += 4 )
<span class="lineNum">     944 </span>            :     {
<span class="lineNum">     945 </span>            :         _AccTp v0 = a[i], v1 = a[i+1], v2 = a[i+2], v3 = a[i+3];
<span class="lineNum">     946 </span>            :         s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
<span class="lineNum">     947 </span>            :     }
<span class="lineNum">     948 </span>            : #endif
<span class="lineNum">     949 </span>            :     for( ; i &lt; n; i++ )
<span class="lineNum">     950 </span>            :     {
<span class="lineNum">     951 </span>            :         _AccTp v = a[i];
<span class="lineNum">     952 </span>            :         s += v*v;
<span class="lineNum">     953 </span>            :     }
<span class="lineNum">     954 </span>            :     return s;
<span class="lineNum">     955 </span>            : }
<span class="lineNum">     956 </span>            : 
<span class="lineNum">     957 </span>            : 
<span class="lineNum">     958 </span>            : template&lt;typename _Tp, typename _AccTp&gt; static inline
<span class="lineNum">     959 </span>            : _AccTp normL1(const _Tp* a, int n)
<span class="lineNum">     960 </span>            : {
<span class="lineNum">     961 </span>            :     _AccTp s = 0;
<span class="lineNum">     962 </span>            :     int i = 0;
<span class="lineNum">     963 </span>            : #if CV_ENABLE_UNROLLED
<span class="lineNum">     964 </span>            :     for(; i &lt;= n - 4; i += 4 )
<span class="lineNum">     965 </span>            :     {
<span class="lineNum">     966 </span>            :         s += (_AccTp)fast_abs(a[i]) + (_AccTp)fast_abs(a[i+1]) +
<span class="lineNum">     967 </span>            :             (_AccTp)fast_abs(a[i+2]) + (_AccTp)fast_abs(a[i+3]);
<span class="lineNum">     968 </span>            :     }
<span class="lineNum">     969 </span>            : #endif
<span class="lineNum">     970 </span>            :     for( ; i &lt; n; i++ )
<span class="lineNum">     971 </span>            :         s += fast_abs(a[i]);
<span class="lineNum">     972 </span>            :     return s;
<span class="lineNum">     973 </span>            : }
<span class="lineNum">     974 </span>            : 
<span class="lineNum">     975 </span>            : 
<span class="lineNum">     976 </span>            : template&lt;typename _Tp, typename _AccTp&gt; static inline
<span class="lineNum">     977 </span>            : _AccTp normInf(const _Tp* a, int n)
<span class="lineNum">     978 </span>            : {
<span class="lineNum">     979 </span>            :     _AccTp s = 0;
<span class="lineNum">     980 </span>            :     for( int i = 0; i &lt; n; i++ )
<span class="lineNum">     981 </span>            :         s = std::max(s, (_AccTp)fast_abs(a[i]));
<span class="lineNum">     982 </span>            :     return s;
<span class="lineNum">     983 </span>            : }
<span class="lineNum">     984 </span>            : 
<span class="lineNum">     985 </span>            : 
<span class="lineNum">     986 </span>            : template&lt;typename _Tp, typename _AccTp&gt; static inline
<span class="lineNum">     987 </span>            : _AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n)
<span class="lineNum">     988 </span>            : {
<span class="lineNum">     989 </span>            :     _AccTp s = 0;
<span class="lineNum">     990 </span>            :     int i= 0;
<span class="lineNum">     991 </span>            : #if CV_ENABLE_UNROLLED
<span class="lineNum">     992 </span>            :     for(; i &lt;= n - 4; i += 4 )
<span class="lineNum">     993 </span>            :     {
<span class="lineNum">     994 </span>            :         _AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
<span class="lineNum">     995 </span>            :         s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
<span class="lineNum">     996 </span>            :     }
<span class="lineNum">     997 </span>            : #endif
<span class="lineNum">     998 </span>            :     for( ; i &lt; n; i++ )
<span class="lineNum">     999 </span>            :     {
<span class="lineNum">    1000 </span>            :         _AccTp v = _AccTp(a[i] - b[i]);
<span class="lineNum">    1001 </span>            :         s += v*v;
<span class="lineNum">    1002 </span>            :     }
<span class="lineNum">    1003 </span>            :     return s;
<span class="lineNum">    1004 </span>            : }
<span class="lineNum">    1005 </span>            : 
<span class="lineNum">    1006 </span>            : CV_EXPORTS float normL2Sqr_(const float* a, const float* b, int n);
<span class="lineNum">    1007 </span>            : CV_EXPORTS float normL1_(const float* a, const float* b, int n);
<span class="lineNum">    1008 </span>            : CV_EXPORTS int normL1_(const uchar* a, const uchar* b, int n);
<span class="lineNum">    1009 </span>            : CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n);
<span class="lineNum">    1010 </span>            : CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n, int cellSize);
<span class="lineNum">    1011 </span>            : 
<span class="lineNum">    1012 </span>            : template&lt;&gt; inline float normL2Sqr(const float* a, const float* b, int n)
<span class="lineNum">    1013 </span>            : {
<span class="lineNum">    1014 </span>            :     if( n &gt;= 8 )
<span class="lineNum">    1015 </span>            :         return normL2Sqr_(a, b, n);
<span class="lineNum">    1016 </span>            :     float s = 0;
<span class="lineNum">    1017 </span>            :     for( int i = 0; i &lt; n; i++ )
<span class="lineNum">    1018 </span>            :     {
<span class="lineNum">    1019 </span>            :         float v = a[i] - b[i];
<span class="lineNum">    1020 </span>            :         s += v*v;
<span class="lineNum">    1021 </span>            :     }
<span class="lineNum">    1022 </span>            :     return s;
<span class="lineNum">    1023 </span>            : }
<span class="lineNum">    1024 </span>            : 
<span class="lineNum">    1025 </span>            : 
<span class="lineNum">    1026 </span>            : template&lt;typename _Tp, typename _AccTp&gt; static inline
<span class="lineNum">    1027 </span>            : _AccTp normL1(const _Tp* a, const _Tp* b, int n)
<span class="lineNum">    1028 </span>            : {
<span class="lineNum">    1029 </span>            :     _AccTp s = 0;
<span class="lineNum">    1030 </span>            :     int i= 0;
<span class="lineNum">    1031 </span>            : #if CV_ENABLE_UNROLLED
<span class="lineNum">    1032 </span>            :     for(; i &lt;= n - 4; i += 4 )
<span class="lineNum">    1033 </span>            :     {
<span class="lineNum">    1034 </span>            :         _AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
<span class="lineNum">    1035 </span>            :         s += std::abs(v0) + std::abs(v1) + std::abs(v2) + std::abs(v3);
<span class="lineNum">    1036 </span>            :     }
<span class="lineNum">    1037 </span>            : #endif
<span class="lineNum">    1038 </span>            :     for( ; i &lt; n; i++ )
<span class="lineNum">    1039 </span>            :     {
<span class="lineNum">    1040 </span>            :         _AccTp v = _AccTp(a[i] - b[i]);
<span class="lineNum">    1041 </span>            :         s += std::abs(v);
<span class="lineNum">    1042 </span>            :     }
<span class="lineNum">    1043 </span>            :     return s;
<span class="lineNum">    1044 </span>            : }
<span class="lineNum">    1045 </span>            : 
<span class="lineNum">    1046 </span>            : template&lt;&gt; inline float normL1(const float* a, const float* b, int n)
<span class="lineNum">    1047 </span>            : {
<span class="lineNum">    1048 </span>            :     if( n &gt;= 8 )
<span class="lineNum">    1049 </span>            :         return normL1_(a, b, n);
<span class="lineNum">    1050 </span>            :     float s = 0;
<span class="lineNum">    1051 </span>            :     for( int i = 0; i &lt; n; i++ )
<span class="lineNum">    1052 </span>            :     {
<span class="lineNum">    1053 </span>            :         float v = a[i] - b[i];
<span class="lineNum">    1054 </span>            :         s += std::abs(v);
<span class="lineNum">    1055 </span>            :     }
<span class="lineNum">    1056 </span>            :     return s;
<span class="lineNum">    1057 </span>            : }
<span class="lineNum">    1058 </span>            : 
<span class="lineNum">    1059 </span>            : template&lt;&gt; inline int normL1(const uchar* a, const uchar* b, int n)
<span class="lineNum">    1060 </span>            : {
<span class="lineNum">    1061 </span>            :     return normL1_(a, b, n);
<span class="lineNum">    1062 </span>            : }
<span class="lineNum">    1063 </span>            : 
<span class="lineNum">    1064 </span>            : template&lt;typename _Tp, typename _AccTp&gt; static inline
<span class="lineNum">    1065 </span>            : _AccTp normInf(const _Tp* a, const _Tp* b, int n)
<span class="lineNum">    1066 </span>            : {
<span class="lineNum">    1067 </span>            :     _AccTp s = 0;
<span class="lineNum">    1068 </span>            :     for( int i = 0; i &lt; n; i++ )
<span class="lineNum">    1069 </span>            :     {
<span class="lineNum">    1070 </span>            :         _AccTp v0 = a[i] - b[i];
<span class="lineNum">    1071 </span>            :         s = std::max(s, std::abs(v0));
<span class="lineNum">    1072 </span>            :     }
<span class="lineNum">    1073 </span>            :     return s;
<span class="lineNum">    1074 </span>            : }
<span class="lineNum">    1075 </span>            : 
<span class="lineNum">    1076 </span>            : 
<span class="lineNum">    1077 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">    1078 </span>            : double norm(const Matx&lt;_Tp, m, n&gt;&amp; M)
<span class="lineNum">    1079 </span>            : {
<span class="lineNum">    1080 </span>            :     return std::sqrt(normL2Sqr&lt;_Tp, double&gt;(M.val, m*n));
<span class="lineNum">    1081 </span>            : }
<span class="lineNum">    1082 </span>            : 
<span class="lineNum">    1083 </span>            : 
<span class="lineNum">    1084 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">    1085 </span>            : double norm(const Matx&lt;_Tp, m, n&gt;&amp; M, int normType)
<span class="lineNum">    1086 </span>            : {
<span class="lineNum">    1087 </span>            :     return normType == NORM_INF ? (double)normInf&lt;_Tp, typename DataType&lt;_Tp&gt;::work_type&gt;(M.val, m*n) :
<span class="lineNum">    1088 </span>            :         normType == NORM_L1 ? (double)normL1&lt;_Tp, typename DataType&lt;_Tp&gt;::work_type&gt;(M.val, m*n) :
<span class="lineNum">    1089 </span>            :         std::sqrt((double)normL2Sqr&lt;_Tp, typename DataType&lt;_Tp&gt;::work_type&gt;(M.val, m*n));
<span class="lineNum">    1090 </span>            : }
<span class="lineNum">    1091 </span>            : 
<span class="lineNum">    1092 </span>            : 
<span class="lineNum">    1093 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">    1094 </span>            : bool operator == (const Matx&lt;_Tp, m, n&gt;&amp; a, const Matx&lt;_Tp, m, n&gt;&amp; b)
<span class="lineNum">    1095 </span>            : {
<span class="lineNum">    1096 </span>            :     for( int i = 0; i &lt; m*n; i++ )
<span class="lineNum">    1097 </span>            :         if( a.val[i] != b.val[i] ) return false;
<span class="lineNum">    1098 </span>            :     return true;
<span class="lineNum">    1099 </span>            : }
<span class="lineNum">    1100 </span>            : 
<span class="lineNum">    1101 </span>            : template&lt;typename _Tp, int m, int n&gt; static inline
<span class="lineNum">    1102 </span>            : bool operator != (const Matx&lt;_Tp, m, n&gt;&amp; a, const Matx&lt;_Tp, m, n&gt;&amp; b)
<span class="lineNum">    1103 </span>            : {
<span class="lineNum">    1104 </span>            :     return !(a == b);
<span class="lineNum">    1105 </span>            : }
<span class="lineNum">    1106 </span>            : 
<span class="lineNum">    1107 </span>            : 
<span class="lineNum">    1108 </span>            : template&lt;typename _Tp, typename _T2, int m, int n&gt; static inline
<span class="lineNum">    1109 </span>            : MatxCommaInitializer&lt;_Tp, m, n&gt; operator &lt;&lt; (const Matx&lt;_Tp, m, n&gt;&amp; mtx, _T2 val)
<span class="lineNum">    1110 </span>            : {
<span class="lineNum">    1111 </span>            :     MatxCommaInitializer&lt;_Tp, m, n&gt; commaInitializer((Matx&lt;_Tp, m, n&gt;*)&amp;mtx);
<span class="lineNum">    1112 </span>            :     return (commaInitializer, val);
<span class="lineNum">    1113 </span>            : }
<span class="lineNum">    1114 </span>            : 
<span class="lineNum">    1115 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">    1116 </span>            : MatxCommaInitializer&lt;_Tp, m, n&gt;::MatxCommaInitializer(Matx&lt;_Tp, m, n&gt;* _mtx)
<span class="lineNum">    1117 </span>            :     : dst(_mtx), idx(0)
<span class="lineNum">    1118 </span>            : {}
<span class="lineNum">    1119 </span>            : 
<span class="lineNum">    1120 </span>            : template&lt;typename _Tp, int m, int n&gt; template&lt;typename _T2&gt; inline
<span class="lineNum">    1121 </span>            : MatxCommaInitializer&lt;_Tp, m, n&gt;&amp; MatxCommaInitializer&lt;_Tp, m, n&gt;::operator , (_T2 value)
<span class="lineNum">    1122 </span>            : {
<span class="lineNum">    1123 </span>            :     CV_DbgAssert( idx &lt; m*n );
<span class="lineNum">    1124 </span>            :     dst-&gt;val[idx++] = saturate_cast&lt;_Tp&gt;(value);
<span class="lineNum">    1125 </span>            :     return *this;
<span class="lineNum">    1126 </span>            : }
<span class="lineNum">    1127 </span>            : 
<span class="lineNum">    1128 </span>            : template&lt;typename _Tp, int m, int n&gt; inline
<span class="lineNum">    1129 </span>            : Matx&lt;_Tp, m, n&gt; MatxCommaInitializer&lt;_Tp, m, n&gt;::operator *() const
<span class="lineNum">    1130 </span>            : {
<span class="lineNum">    1131 </span>            :     CV_DbgAssert( idx == n*m );
<span class="lineNum">    1132 </span>            :     return *dst;
<span class="lineNum">    1133 </span>            : }
<span class="lineNum">    1134 </span>            : 
<span class="lineNum">    1135 </span>            : /////////////////////////// short vector (Vec) /////////////////////////////
<span class="lineNum">    1136 </span>            : 
<span class="lineNum">    1137 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec()
<span class="lineNum">    1138 </span>            : {}
<span class="lineNum">    1139 </span>            : 
<span class="lineNum">    1140 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(_Tp v0)
<span class="lineNum">    1141 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(v0)
<span class="lineNum">    1142 </span>            : {}
<span class="lineNum">    1143 </span>            : 
<span class="lineNum">    1144 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(_Tp v0, _Tp v1)
<span class="lineNum">    1145 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(v0, v1)
<span class="lineNum">    1146 </span>            : {}
<span class="lineNum">    1147 </span>            : 
<span class="lineNum">    1148 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(_Tp v0, _Tp v1, _Tp v2)
<span class="lineNum">    1149 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(v0, v1, v2)
<span class="lineNum">    1150 </span>            : {}
<span class="lineNum">    1151 </span>            : 
<span class="lineNum">    1152 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3)
<span class="lineNum">    1153 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(v0, v1, v2, v3)
<span class="lineNum">    1154 </span>            : {}
<span class="lineNum">    1155 </span>            : 
<span class="lineNum">    1156 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4)
<span class="lineNum">    1157 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(v0, v1, v2, v3, v4)
<span class="lineNum">    1158 </span>            : {}
<span class="lineNum">    1159 </span>            : 
<span class="lineNum">    1160 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5)
<span class="lineNum">    1161 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(v0, v1, v2, v3, v4, v5)
<span class="lineNum">    1162 </span>            : {}
<span class="lineNum">    1163 </span>            : 
<span class="lineNum">    1164 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
<span class="lineNum">    1165 </span>            :                                                         _Tp v4, _Tp v5, _Tp v6)
<span class="lineNum">    1166 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(v0, v1, v2, v3, v4, v5, v6)
<span class="lineNum">    1167 </span>            : {}
<span class="lineNum">    1168 </span>            : 
<span class="lineNum">    1169 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
<span class="lineNum">    1170 </span>            :                                                         _Tp v4, _Tp v5, _Tp v6, _Tp v7)
<span class="lineNum">    1171 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(v0, v1, v2, v3, v4, v5, v6, v7)
<span class="lineNum">    1172 </span>            : {}
<span class="lineNum">    1173 </span>            : 
<span class="lineNum">    1174 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
<span class="lineNum">    1175 </span>            :                                                         _Tp v4, _Tp v5, _Tp v6, _Tp v7,
<span class="lineNum">    1176 </span>            :                                                         _Tp v8)
<span class="lineNum">    1177 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(v0, v1, v2, v3, v4, v5, v6, v7, v8)
<span class="lineNum">    1178 </span>            : {}
<span class="lineNum">    1179 </span>            : 
<span class="lineNum">    1180 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
<span class="lineNum">    1181 </span>            :                                                         _Tp v4, _Tp v5, _Tp v6, _Tp v7,
<span class="lineNum">    1182 </span>            :                                                         _Tp v8, _Tp v9)
<span class="lineNum">    1183 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
<span class="lineNum">    1184 </span>            : {}
<span class="lineNum">    1185 </span>            : 
<span class="lineNum">    1186 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(const _Tp* values)
<span class="lineNum">    1187 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(values)
<span class="lineNum">    1188 </span>            : {}
<span class="lineNum">    1189 </span>            : 
<span class="lineNum">    1190 </span>            : 
<span class="lineNum">    1191 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::Vec(const Vec&lt;_Tp, cn&gt;&amp; m)
<span class="lineNum">    1192 </span>            :     : Matx&lt;_Tp, cn, 1&gt;(m.val)
<span class="lineNum">    1193 </span>            : {}
<span class="lineNum">    1194 </span>            : 
<span class="lineNum">    1195 </span>            : template&lt;typename _Tp, int cn&gt; inline
<span class="lineNum">    1196 </span>            : Vec&lt;_Tp, cn&gt;::Vec(const Matx&lt;_Tp, cn, 1&gt;&amp; a, const Matx&lt;_Tp, cn, 1&gt;&amp; b, Matx_AddOp op)
<span class="lineNum">    1197 </span>            : : Matx&lt;_Tp, cn, 1&gt;(a, b, op)
<span class="lineNum">    1198 </span>            : {}
<span class="lineNum">    1199 </span>            : 
<span class="lineNum">    1200 </span>            : template&lt;typename _Tp, int cn&gt; inline
<span class="lineNum">    1201 </span>            : Vec&lt;_Tp, cn&gt;::Vec(const Matx&lt;_Tp, cn, 1&gt;&amp; a, const Matx&lt;_Tp, cn, 1&gt;&amp; b, Matx_SubOp op)
<span class="lineNum">    1202 </span>            : : Matx&lt;_Tp, cn, 1&gt;(a, b, op)
<span class="lineNum">    1203 </span>            : {}
<span class="lineNum">    1204 </span>            : 
<span class="lineNum">    1205 </span>            : template&lt;typename _Tp, int cn&gt; template&lt;typename _T2&gt; inline
<span class="lineNum">    1206 </span>            : Vec&lt;_Tp, cn&gt;::Vec(const Matx&lt;_Tp, cn, 1&gt;&amp; a, _T2 alpha, Matx_ScaleOp op)
<span class="lineNum">    1207 </span>            : : Matx&lt;_Tp, cn, 1&gt;(a, alpha, op)
<span class="lineNum">    1208 </span>            : {}
<span class="lineNum">    1209 </span>            : 
<span class="lineNum">    1210 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt; Vec&lt;_Tp, cn&gt;::all(_Tp alpha)
<span class="lineNum">    1211 </span>            : {
<span class="lineNum">    1212 </span>            :     Vec v;
<span class="lineNum">    1213 </span>            :     for( int i = 0; i &lt; cn; i++ ) v.val[i] = alpha;
<span class="lineNum">    1214 </span>            :     return v;
<span class="lineNum">    1215 </span>            : }
<span class="lineNum">    1216 </span>            : 
<span class="lineNum">    1217 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt; Vec&lt;_Tp, cn&gt;::mul(const Vec&lt;_Tp, cn&gt;&amp; v) const
<span class="lineNum">    1218 </span>            : {
<span class="lineNum">    1219 </span>            :     Vec&lt;_Tp, cn&gt; w;
<span class="lineNum">    1220 </span>            :     for( int i = 0; i &lt; cn; i++ ) w.val[i] = saturate_cast&lt;_Tp&gt;(this-&gt;val[i]*v.val[i]);
<span class="lineNum">    1221 </span>            :     return w;
<span class="lineNum">    1222 </span>            : }
<span class="lineNum">    1223 </span>            : 
<span class="lineNum">    1224 </span>            : template&lt;typename _Tp&gt; Vec&lt;_Tp, 2&gt; conjugate(const Vec&lt;_Tp, 2&gt;&amp; v)
<span class="lineNum">    1225 </span>            : {
<span class="lineNum">    1226 </span>            :     return Vec&lt;_Tp, 2&gt;(v[0], -v[1]);
<span class="lineNum">    1227 </span>            : }
<span class="lineNum">    1228 </span>            : 
<span class="lineNum">    1229 </span>            : template&lt;typename _Tp&gt; Vec&lt;_Tp, 4&gt; conjugate(const Vec&lt;_Tp, 4&gt;&amp; v)
<span class="lineNum">    1230 </span>            : {
<span class="lineNum">    1231 </span>            :     return Vec&lt;_Tp, 4&gt;(v[0], -v[1], -v[2], -v[3]);
<span class="lineNum">    1232 </span>            : }
<span class="lineNum">    1233 </span>            : 
<span class="lineNum">    1234 </span>            : template&lt;&gt; inline Vec&lt;float, 2&gt; Vec&lt;float, 2&gt;::conj() const
<span class="lineNum">    1235 </span>            : {
<span class="lineNum">    1236 </span>            :     return conjugate(*this);
<span class="lineNum">    1237 </span>            : }
<span class="lineNum">    1238 </span>            : 
<span class="lineNum">    1239 </span>            : template&lt;&gt; inline Vec&lt;double, 2&gt; Vec&lt;double, 2&gt;::conj() const
<span class="lineNum">    1240 </span>            : {
<span class="lineNum">    1241 </span>            :     return conjugate(*this);
<span class="lineNum">    1242 </span>            : }
<span class="lineNum">    1243 </span>            : 
<span class="lineNum">    1244 </span>            : template&lt;&gt; inline Vec&lt;float, 4&gt; Vec&lt;float, 4&gt;::conj() const
<span class="lineNum">    1245 </span>            : {
<span class="lineNum">    1246 </span>            :     return conjugate(*this);
<span class="lineNum">    1247 </span>            : }
<span class="lineNum">    1248 </span>            : 
<span class="lineNum">    1249 </span>            : template&lt;&gt; inline Vec&lt;double, 4&gt; Vec&lt;double, 4&gt;::conj() const
<span class="lineNum">    1250 </span>            : {
<span class="lineNum">    1251 </span>            :     return conjugate(*this);
<span class="lineNum">    1252 </span>            : }
<span class="lineNum">    1253 </span>            : 
<span class="lineNum">    1254 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt; Vec&lt;_Tp, cn&gt;::cross(const Vec&lt;_Tp, cn&gt;&amp;) const
<span class="lineNum">    1255 </span>            : {
<span class="lineNum">    1256 </span>            :     CV_Error(CV_StsError, &quot;for arbitrary-size vector there is no cross-product defined&quot;);
<span class="lineNum">    1257 </span>            :     return Vec&lt;_Tp, cn&gt;();
<span class="lineNum">    1258 </span>            : }
<span class="lineNum">    1259 </span>            : 
<span class="lineNum">    1260 </span>            : template&lt;typename _Tp, int cn&gt; template&lt;typename T2&gt;
<span class="lineNum">    1261 </span>            : inline Vec&lt;_Tp, cn&gt;::operator Vec&lt;T2, cn&gt;() const
<span class="lineNum">    1262 </span>            : {
<span class="lineNum">    1263 </span>            :     Vec&lt;T2, cn&gt; v;
<span class="lineNum">    1264 </span>            :     for( int i = 0; i &lt; cn; i++ ) v.val[i] = saturate_cast&lt;T2&gt;(this-&gt;val[i]);
<span class="lineNum">    1265 </span>            :     return v;
<span class="lineNum">    1266 </span>            : }
<span class="lineNum">    1267 </span>            : 
<span class="lineNum">    1268 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt;::operator CvScalar() const
<span class="lineNum">    1269 </span>            : {
<span class="lineNum">    1270 </span>            :     CvScalar s = {{0,0,0,0}};
<span class="lineNum">    1271 </span>            :     int i;
<span class="lineNum">    1272 </span>            :     for( i = 0; i &lt; std::min(cn, 4); i++ ) s.val[i] = this-&gt;val[i];
<span class="lineNum">    1273 </span>            :     for( ; i &lt; 4; i++ ) s.val[i] = 0;
<span class="lineNum">    1274 </span>            :     return s;
<span class="lineNum">    1275 </span>            : }
<span class="lineNum">    1276 </span>            : 
<span class="lineNum">    1277 </span>            : template&lt;typename _Tp, int cn&gt; inline const _Tp&amp; Vec&lt;_Tp, cn&gt;::operator [](int i) const
<span class="lineNum">    1278 </span>            : {
<span class="lineNum">    1279 </span>            :     CV_DbgAssert( (unsigned)i &lt; (unsigned)cn );
<span class="lineNum">    1280 </span>            :     return this-&gt;val[i];
<span class="lineNum">    1281 </span>            : }
<span class="lineNum">    1282 </span>            : 
<span class="lineNum">    1283 </span>            : template&lt;typename _Tp, int cn&gt; inline _Tp&amp; Vec&lt;_Tp, cn&gt;::operator [](int i)
<span class="lineNum">    1284 </span>            : {
<span class="lineNum">    1285 </span>            :     CV_DbgAssert( (unsigned)i &lt; (unsigned)cn );
<span class="lineNum">    1286 </span>            :     return this-&gt;val[i];
<span class="lineNum">    1287 </span>            : }
<span class="lineNum">    1288 </span>            : 
<span class="lineNum">    1289 </span>            : template&lt;typename _Tp, int cn&gt; inline const _Tp&amp; Vec&lt;_Tp, cn&gt;::operator ()(int i) const
<span class="lineNum">    1290 </span>            : {
<span class="lineNum">    1291 </span>            :     CV_DbgAssert( (unsigned)i &lt; (unsigned)cn );
<span class="lineNum">    1292 </span>            :     return this-&gt;val[i];
<span class="lineNum">    1293 </span>            : }
<span class="lineNum">    1294 </span>            : 
<span class="lineNum">    1295 </span>            : template&lt;typename _Tp, int cn&gt; inline _Tp&amp; Vec&lt;_Tp, cn&gt;::operator ()(int i)
<span class="lineNum">    1296 </span>            : {
<span class="lineNum">    1297 </span>            :     CV_DbgAssert( (unsigned)i &lt; (unsigned)cn );
<span class="lineNum">    1298 </span>            :     return this-&gt;val[i];
<span class="lineNum">    1299 </span>            : }
<span class="lineNum">    1300 </span>            : 
<span class="lineNum">    1301 </span>            : template&lt;typename _Tp1, typename _Tp2, int cn&gt; static inline Vec&lt;_Tp1, cn&gt;&amp;
<span class="lineNum">    1302 </span>            : operator += (Vec&lt;_Tp1, cn&gt;&amp; a, const Vec&lt;_Tp2, cn&gt;&amp; b)
<span class="lineNum">    1303 </span>            : {
<span class="lineNum">    1304 </span>            :     for( int i = 0; i &lt; cn; i++ )
<span class="lineNum">    1305 </span>            :         a.val[i] = saturate_cast&lt;_Tp1&gt;(a.val[i] + b.val[i]);
<span class="lineNum">    1306 </span>            :     return a;
<span class="lineNum">    1307 </span>            : }
<span class="lineNum">    1308 </span>            : 
<span class="lineNum">    1309 </span>            : template&lt;typename _Tp1, typename _Tp2, int cn&gt; static inline Vec&lt;_Tp1, cn&gt;&amp;
<span class="lineNum">    1310 </span>            : operator -= (Vec&lt;_Tp1, cn&gt;&amp; a, const Vec&lt;_Tp2, cn&gt;&amp; b)
<span class="lineNum">    1311 </span>            : {
<span class="lineNum">    1312 </span>            :     for( int i = 0; i &lt; cn; i++ )
<span class="lineNum">    1313 </span>            :         a.val[i] = saturate_cast&lt;_Tp1&gt;(a.val[i] - b.val[i]);
<span class="lineNum">    1314 </span>            :     return a;
<span class="lineNum">    1315 </span>            : }
<span class="lineNum">    1316 </span>            : 
<span class="lineNum">    1317 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1318 </span>            : operator + (const Vec&lt;_Tp, cn&gt;&amp; a, const Vec&lt;_Tp, cn&gt;&amp; b)
<span class="lineNum">    1319 </span>            : {
<span class="lineNum">    1320 </span>            :     return Vec&lt;_Tp, cn&gt;(a, b, Matx_AddOp());
<span class="lineNum">    1321 </span>            : }
<span class="lineNum">    1322 </span>            : 
<span class="lineNum">    1323 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1324 </span>            : operator - (const Vec&lt;_Tp, cn&gt;&amp; a, const Vec&lt;_Tp, cn&gt;&amp; b)
<span class="lineNum">    1325 </span>            : {
<span class="lineNum">    1326 </span>            :     return Vec&lt;_Tp, cn&gt;(a, b, Matx_SubOp());
<span class="lineNum">    1327 </span>            : }
<span class="lineNum">    1328 </span>            : 
<span class="lineNum">    1329 </span>            : template&lt;typename _Tp, int cn&gt; static inline
<span class="lineNum">    1330 </span>            : Vec&lt;_Tp, cn&gt;&amp; operator *= (Vec&lt;_Tp, cn&gt;&amp; a, int alpha)
<span class="lineNum">    1331 </span>            : {
<span class="lineNum">    1332 </span>            :     for( int i = 0; i &lt; cn; i++ )
<span class="lineNum">    1333 </span>            :         a[i] = saturate_cast&lt;_Tp&gt;(a[i]*alpha);
<span class="lineNum">    1334 </span>            :     return a;
<span class="lineNum">    1335 </span>            : }
<span class="lineNum">    1336 </span>            : 
<span class="lineNum">    1337 </span>            : template&lt;typename _Tp, int cn&gt; static inline
<span class="lineNum">    1338 </span>            : Vec&lt;_Tp, cn&gt;&amp; operator *= (Vec&lt;_Tp, cn&gt;&amp; a, float alpha)
<span class="lineNum">    1339 </span>            : {
<span class="lineNum">    1340 </span>            :     for( int i = 0; i &lt; cn; i++ )
<span class="lineNum">    1341 </span>            :         a[i] = saturate_cast&lt;_Tp&gt;(a[i]*alpha);
<span class="lineNum">    1342 </span>            :     return a;
<span class="lineNum">    1343 </span>            : }
<span class="lineNum">    1344 </span>            : 
<span class="lineNum">    1345 </span>            : template&lt;typename _Tp, int cn&gt; static inline
<span class="lineNum">    1346 </span>            : Vec&lt;_Tp, cn&gt;&amp; operator *= (Vec&lt;_Tp, cn&gt;&amp; a, double alpha)
<span class="lineNum">    1347 </span>            : {
<span class="lineNum">    1348 </span>            :     for( int i = 0; i &lt; cn; i++ )
<span class="lineNum">    1349 </span>            :         a[i] = saturate_cast&lt;_Tp&gt;(a[i]*alpha);
<span class="lineNum">    1350 </span>            :     return a;
<span class="lineNum">    1351 </span>            : }
<span class="lineNum">    1352 </span>            : 
<span class="lineNum">    1353 </span>            : template&lt;typename _Tp, int cn&gt; static inline
<span class="lineNum">    1354 </span>            : Vec&lt;_Tp, cn&gt;&amp; operator /= (Vec&lt;_Tp, cn&gt;&amp; a, int alpha)
<span class="lineNum">    1355 </span>            : {
<span class="lineNum">    1356 </span>            :     double ialpha = 1./alpha;
<span class="lineNum">    1357 </span>            :     for( int i = 0; i &lt; cn; i++ )
<span class="lineNum">    1358 </span>            :         a[i] = saturate_cast&lt;_Tp&gt;(a[i]*ialpha);
<span class="lineNum">    1359 </span>            :     return a;
<span class="lineNum">    1360 </span>            : }
<span class="lineNum">    1361 </span>            : 
<span class="lineNum">    1362 </span>            : template&lt;typename _Tp, int cn&gt; static inline
<span class="lineNum">    1363 </span>            : Vec&lt;_Tp, cn&gt;&amp; operator /= (Vec&lt;_Tp, cn&gt;&amp; a, float alpha)
<span class="lineNum">    1364 </span>            : {
<span class="lineNum">    1365 </span>            :     float ialpha = 1.f/alpha;
<span class="lineNum">    1366 </span>            :     for( int i = 0; i &lt; cn; i++ )
<span class="lineNum">    1367 </span>            :         a[i] = saturate_cast&lt;_Tp&gt;(a[i]*ialpha);
<span class="lineNum">    1368 </span>            :     return a;
<span class="lineNum">    1369 </span>            : }
<span class="lineNum">    1370 </span>            : 
<span class="lineNum">    1371 </span>            : template&lt;typename _Tp, int cn&gt; static inline
<span class="lineNum">    1372 </span>            : Vec&lt;_Tp, cn&gt;&amp; operator /= (Vec&lt;_Tp, cn&gt;&amp; a, double alpha)
<span class="lineNum">    1373 </span>            : {
<span class="lineNum">    1374 </span>            :     double ialpha = 1./alpha;
<span class="lineNum">    1375 </span>            :     for( int i = 0; i &lt; cn; i++ )
<span class="lineNum">    1376 </span>            :         a[i] = saturate_cast&lt;_Tp&gt;(a[i]*ialpha);
<span class="lineNum">    1377 </span>            :     return a;
<span class="lineNum">    1378 </span>            : }
<span class="lineNum">    1379 </span>            : 
<span class="lineNum">    1380 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1381 </span>            : operator * (const Vec&lt;_Tp, cn&gt;&amp; a, int alpha)
<span class="lineNum">    1382 </span>            : {
<span class="lineNum">    1383 </span>            :     return Vec&lt;_Tp, cn&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">    1384 </span>            : }
<span class="lineNum">    1385 </span>            : 
<span class="lineNum">    1386 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1387 </span>            : operator * (int alpha, const Vec&lt;_Tp, cn&gt;&amp; a)
<span class="lineNum">    1388 </span>            : {
<span class="lineNum">    1389 </span>            :     return Vec&lt;_Tp, cn&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">    1390 </span>            : }
<span class="lineNum">    1391 </span>            : 
<span class="lineNum">    1392 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1393 </span>            : operator * (const Vec&lt;_Tp, cn&gt;&amp; a, float alpha)
<span class="lineNum">    1394 </span>            : {
<span class="lineNum">    1395 </span>            :     return Vec&lt;_Tp, cn&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">    1396 </span>            : }
<span class="lineNum">    1397 </span>            : 
<span class="lineNum">    1398 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1399 </span>            : operator * (float alpha, const Vec&lt;_Tp, cn&gt;&amp; a)
<span class="lineNum">    1400 </span>            : {
<span class="lineNum">    1401 </span>            :     return Vec&lt;_Tp, cn&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">    1402 </span>            : }
<span class="lineNum">    1403 </span>            : 
<span class="lineNum">    1404 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1405 </span>            : operator * (const Vec&lt;_Tp, cn&gt;&amp; a, double alpha)
<span class="lineNum">    1406 </span>            : {
<span class="lineNum">    1407 </span>            :     return Vec&lt;_Tp, cn&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">    1408 </span>            : }
<span class="lineNum">    1409 </span>            : 
<span class="lineNum">    1410 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1411 </span>            : operator * (double alpha, const Vec&lt;_Tp, cn&gt;&amp; a)
<span class="lineNum">    1412 </span>            : {
<span class="lineNum">    1413 </span>            :     return Vec&lt;_Tp, cn&gt;(a, alpha, Matx_ScaleOp());
<span class="lineNum">    1414 </span>            : }
<span class="lineNum">    1415 </span>            : 
<span class="lineNum">    1416 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1417 </span>            : operator / (const Vec&lt;_Tp, cn&gt;&amp; a, int alpha)
<span class="lineNum">    1418 </span>            : {
<span class="lineNum">    1419 </span>            :     return Vec&lt;_Tp, cn&gt;(a, 1./alpha, Matx_ScaleOp());
<span class="lineNum">    1420 </span>            : }
<span class="lineNum">    1421 </span>            : 
<span class="lineNum">    1422 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1423 </span>            : operator / (const Vec&lt;_Tp, cn&gt;&amp; a, float alpha)
<span class="lineNum">    1424 </span>            : {
<span class="lineNum">    1425 </span>            :     return Vec&lt;_Tp, cn&gt;(a, 1.f/alpha, Matx_ScaleOp());
<span class="lineNum">    1426 </span>            : }
<span class="lineNum">    1427 </span>            : 
<span class="lineNum">    1428 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1429 </span>            : operator / (const Vec&lt;_Tp, cn&gt;&amp; a, double alpha)
<span class="lineNum">    1430 </span>            : {
<span class="lineNum">    1431 </span>            :     return Vec&lt;_Tp, cn&gt;(a, 1./alpha, Matx_ScaleOp());
<span class="lineNum">    1432 </span>            : }
<span class="lineNum">    1433 </span>            : 
<span class="lineNum">    1434 </span>            : template&lt;typename _Tp, int cn&gt; static inline Vec&lt;_Tp, cn&gt;
<span class="lineNum">    1435 </span>            : operator - (const Vec&lt;_Tp, cn&gt;&amp; a)
<span class="lineNum">    1436 </span>            : {
<span class="lineNum">    1437 </span>            :     Vec&lt;_Tp,cn&gt; t;
<span class="lineNum">    1438 </span>            :     for( int i = 0; i &lt; cn; i++ ) t.val[i] = saturate_cast&lt;_Tp&gt;(-a.val[i]);
<span class="lineNum">    1439 </span>            :     return t;
<span class="lineNum">    1440 </span>            : }
<span class="lineNum">    1441 </span>            : 
<span class="lineNum">    1442 </span>            : template&lt;typename _Tp&gt; inline Vec&lt;_Tp, 4&gt; operator * (const Vec&lt;_Tp, 4&gt;&amp; v1, const Vec&lt;_Tp, 4&gt;&amp; v2)
<span class="lineNum">    1443 </span>            : {
<span class="lineNum">    1444 </span>            :     return Vec&lt;_Tp, 4&gt;(saturate_cast&lt;_Tp&gt;(v1[0]*v2[0] - v1[1]*v2[1] - v1[2]*v2[2] - v1[3]*v2[3]),
<span class="lineNum">    1445 </span>            :                        saturate_cast&lt;_Tp&gt;(v1[0]*v2[1] + v1[1]*v2[0] + v1[2]*v2[3] - v1[3]*v2[2]),
<span class="lineNum">    1446 </span>            :                        saturate_cast&lt;_Tp&gt;(v1[0]*v2[2] - v1[1]*v2[3] + v1[2]*v2[0] + v1[3]*v2[1]),
<span class="lineNum">    1447 </span>            :                        saturate_cast&lt;_Tp&gt;(v1[0]*v2[3] + v1[1]*v2[2] - v1[2]*v2[1] + v1[3]*v2[0]));
<span class="lineNum">    1448 </span>            : }
<span class="lineNum">    1449 </span>            : 
<span class="lineNum">    1450 </span>            : template&lt;typename _Tp&gt; inline Vec&lt;_Tp, 4&gt;&amp; operator *= (Vec&lt;_Tp, 4&gt;&amp; v1, const Vec&lt;_Tp, 4&gt;&amp; v2)
<span class="lineNum">    1451 </span>            : {
<span class="lineNum">    1452 </span>            :     v1 = v1 * v2;
<span class="lineNum">    1453 </span>            :     return v1;
<span class="lineNum">    1454 </span>            : }
<span class="lineNum">    1455 </span>            : 
<span class="lineNum">    1456 </span>            : template&lt;&gt; inline Vec&lt;float, 3&gt; Vec&lt;float, 3&gt;::cross(const Vec&lt;float, 3&gt;&amp; v) const
<span class="lineNum">    1457 </span>            : {
<span class="lineNum">    1458 </span>            :     return Vec&lt;float,3&gt;(val[1]*v.val[2] - val[2]*v.val[1],
<span class="lineNum">    1459 </span>            :                      val[2]*v.val[0] - val[0]*v.val[2],
<span class="lineNum">    1460 </span>            :                      val[0]*v.val[1] - val[1]*v.val[0]);
<span class="lineNum">    1461 </span>            : }
<span class="lineNum">    1462 </span>            : 
<span class="lineNum">    1463 </span>            : template&lt;&gt; inline Vec&lt;double, 3&gt; Vec&lt;double, 3&gt;::cross(const Vec&lt;double, 3&gt;&amp; v) const
<span class="lineNum">    1464 </span>            : {
<span class="lineNum">    1465 </span>            :     return Vec&lt;double,3&gt;(val[1]*v.val[2] - val[2]*v.val[1],
<span class="lineNum">    1466 </span>            :                      val[2]*v.val[0] - val[0]*v.val[2],
<span class="lineNum">    1467 </span>            :                      val[0]*v.val[1] - val[1]*v.val[0]);
<span class="lineNum">    1468 </span>            : }
<span class="lineNum">    1469 </span>            : 
<span class="lineNum">    1470 </span>            : template&lt;typename _Tp, int cn&gt; inline Vec&lt;_Tp, cn&gt; normalize(const Vec&lt;_Tp, cn&gt;&amp; v)
<span class="lineNum">    1471 </span>            : {
<span class="lineNum">    1472 </span>            :     double nv = norm(v);
<span class="lineNum">    1473 </span>            :     return v * (nv ? 1./nv : 0.);
<span class="lineNum">    1474 </span>            : }
<span class="lineNum">    1475 </span>            : 
<span class="lineNum">    1476 </span>            : template&lt;typename _Tp, typename _T2, int cn&gt; static inline
<span class="lineNum">    1477 </span>            : VecCommaInitializer&lt;_Tp, cn&gt; operator &lt;&lt; (const Vec&lt;_Tp, cn&gt;&amp; vec, _T2 val)
<span class="lineNum">    1478 </span>            : {
<span class="lineNum">    1479 </span>            :     VecCommaInitializer&lt;_Tp, cn&gt; commaInitializer((Vec&lt;_Tp, cn&gt;*)&amp;vec);
<span class="lineNum">    1480 </span>            :     return (commaInitializer, val);
<span class="lineNum">    1481 </span>            : }
<span class="lineNum">    1482 </span>            : 
<span class="lineNum">    1483 </span>            : template&lt;typename _Tp, int cn&gt; inline
<span class="lineNum">    1484 </span>            : VecCommaInitializer&lt;_Tp, cn&gt;::VecCommaInitializer(Vec&lt;_Tp, cn&gt;* _vec)
<span class="lineNum">    1485 </span>            :     : MatxCommaInitializer&lt;_Tp, cn, 1&gt;(_vec)
<span class="lineNum">    1486 </span>            : {}
<span class="lineNum">    1487 </span>            : 
<span class="lineNum">    1488 </span>            : template&lt;typename _Tp, int cn&gt; template&lt;typename _T2&gt; inline
<span class="lineNum">    1489 </span>            : VecCommaInitializer&lt;_Tp, cn&gt;&amp; VecCommaInitializer&lt;_Tp, cn&gt;::operator , (_T2 value)
<span class="lineNum">    1490 </span>            : {
<span class="lineNum">    1491 </span>            :     CV_DbgAssert( this-&gt;idx &lt; cn );
<span class="lineNum">    1492 </span>            :     this-&gt;dst-&gt;val[this-&gt;idx++] = saturate_cast&lt;_Tp&gt;(value);
<span class="lineNum">    1493 </span>            :     return *this;
<span class="lineNum">    1494 </span>            : }
<span class="lineNum">    1495 </span>            : 
<span class="lineNum">    1496 </span>            : template&lt;typename _Tp, int cn&gt; inline
<span class="lineNum">    1497 </span>            : Vec&lt;_Tp, cn&gt; VecCommaInitializer&lt;_Tp, cn&gt;::operator *() const
<span class="lineNum">    1498 </span>            : {
<span class="lineNum">    1499 </span>            :     CV_DbgAssert( this-&gt;idx == cn );
<span class="lineNum">    1500 </span>            :     return *this-&gt;dst;
<span class="lineNum">    1501 </span>            : }
<span class="lineNum">    1502 </span>            : 
<span class="lineNum">    1503 </span>            : //////////////////////////////// Complex //////////////////////////////
<span class="lineNum">    1504 </span>            : 
<span class="lineNum">    1505 </span>            : template&lt;typename _Tp&gt; inline Complex&lt;_Tp&gt;::Complex() : re(0), im(0) {}
<span class="lineNum">    1506 </span>            : template&lt;typename _Tp&gt; inline Complex&lt;_Tp&gt;::Complex( _Tp _re, _Tp _im ) : re(_re), im(_im) {}
<span class="lineNum">    1507 </span>            : template&lt;typename _Tp&gt; template&lt;typename T2&gt; inline Complex&lt;_Tp&gt;::operator Complex&lt;T2&gt;() const
<span class="lineNum">    1508 </span>            : { return Complex&lt;T2&gt;(saturate_cast&lt;T2&gt;(re), saturate_cast&lt;T2&gt;(im)); }
<span class="lineNum">    1509 </span>            : template&lt;typename _Tp&gt; inline Complex&lt;_Tp&gt; Complex&lt;_Tp&gt;::conj() const
<span class="lineNum">    1510 </span>            : { return Complex&lt;_Tp&gt;(re, -im); }
<span class="lineNum">    1511 </span>            : 
<span class="lineNum">    1512 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1513 </span>            : bool operator == (const Complex&lt;_Tp&gt;&amp; a, const Complex&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1514 </span>            : { return a.re == b.re &amp;&amp; a.im == b.im; }
<span class="lineNum">    1515 </span>            : 
<span class="lineNum">    1516 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1517 </span>            : bool operator != (const Complex&lt;_Tp&gt;&amp; a, const Complex&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1518 </span>            : { return a.re != b.re || a.im != b.im; }
<span class="lineNum">    1519 </span>            : 
<span class="lineNum">    1520 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1521 </span>            : Complex&lt;_Tp&gt; operator + (const Complex&lt;_Tp&gt;&amp; a, const Complex&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1522 </span>            : { return Complex&lt;_Tp&gt;( a.re + b.re, a.im + b.im ); }
<span class="lineNum">    1523 </span>            : 
<span class="lineNum">    1524 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1525 </span>            : Complex&lt;_Tp&gt;&amp; operator += (Complex&lt;_Tp&gt;&amp; a, const Complex&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1526 </span>            : { a.re += b.re; a.im += b.im; return a; }
<span class="lineNum">    1527 </span>            : 
<span class="lineNum">    1528 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1529 </span>            : Complex&lt;_Tp&gt; operator - (const Complex&lt;_Tp&gt;&amp; a, const Complex&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1530 </span>            : { return Complex&lt;_Tp&gt;( a.re - b.re, a.im - b.im ); }
<span class="lineNum">    1531 </span>            : 
<span class="lineNum">    1532 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1533 </span>            : Complex&lt;_Tp&gt;&amp; operator -= (Complex&lt;_Tp&gt;&amp; a, const Complex&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1534 </span>            : { a.re -= b.re; a.im -= b.im; return a; }
<span class="lineNum">    1535 </span>            : 
<span class="lineNum">    1536 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1537 </span>            : Complex&lt;_Tp&gt; operator - (const Complex&lt;_Tp&gt;&amp; a)
<span class="lineNum">    1538 </span>            : { return Complex&lt;_Tp&gt;(-a.re, -a.im); }
<span class="lineNum">    1539 </span>            : 
<span class="lineNum">    1540 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1541 </span>            : Complex&lt;_Tp&gt; operator * (const Complex&lt;_Tp&gt;&amp; a, const Complex&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1542 </span>            : { return Complex&lt;_Tp&gt;( a.re*b.re - a.im*b.im, a.re*b.im + a.im*b.re ); }
<span class="lineNum">    1543 </span>            : 
<span class="lineNum">    1544 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1545 </span>            : Complex&lt;_Tp&gt; operator * (const Complex&lt;_Tp&gt;&amp; a, _Tp b)
<span class="lineNum">    1546 </span>            : { return Complex&lt;_Tp&gt;( a.re*b, a.im*b ); }
<span class="lineNum">    1547 </span>            : 
<span class="lineNum">    1548 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1549 </span>            : Complex&lt;_Tp&gt; operator * (_Tp b, const Complex&lt;_Tp&gt;&amp; a)
<span class="lineNum">    1550 </span>            : { return Complex&lt;_Tp&gt;( a.re*b, a.im*b ); }
<span class="lineNum">    1551 </span>            : 
<span class="lineNum">    1552 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1553 </span>            : Complex&lt;_Tp&gt; operator + (const Complex&lt;_Tp&gt;&amp; a, _Tp b)
<span class="lineNum">    1554 </span>            : { return Complex&lt;_Tp&gt;( a.re + b, a.im ); }
<span class="lineNum">    1555 </span>            : 
<span class="lineNum">    1556 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1557 </span>            : Complex&lt;_Tp&gt; operator - (const Complex&lt;_Tp&gt;&amp; a, _Tp b)
<span class="lineNum">    1558 </span>            : { return Complex&lt;_Tp&gt;( a.re - b, a.im ); }
<span class="lineNum">    1559 </span>            : 
<span class="lineNum">    1560 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1561 </span>            : Complex&lt;_Tp&gt; operator + (_Tp b, const Complex&lt;_Tp&gt;&amp; a)
<span class="lineNum">    1562 </span>            : { return Complex&lt;_Tp&gt;( a.re + b, a.im ); }
<span class="lineNum">    1563 </span>            : 
<span class="lineNum">    1564 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1565 </span>            : Complex&lt;_Tp&gt; operator - (_Tp b, const Complex&lt;_Tp&gt;&amp; a)
<span class="lineNum">    1566 </span>            : { return Complex&lt;_Tp&gt;( b - a.re, -a.im ); }
<span class="lineNum">    1567 </span>            : 
<span class="lineNum">    1568 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1569 </span>            : Complex&lt;_Tp&gt;&amp; operator += (Complex&lt;_Tp&gt;&amp; a, _Tp b)
<span class="lineNum">    1570 </span>            : { a.re += b; return a; }
<span class="lineNum">    1571 </span>            : 
<span class="lineNum">    1572 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1573 </span>            : Complex&lt;_Tp&gt;&amp; operator -= (Complex&lt;_Tp&gt;&amp; a, _Tp b)
<span class="lineNum">    1574 </span>            : { a.re -= b; return a; }
<span class="lineNum">    1575 </span>            : 
<span class="lineNum">    1576 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1577 </span>            : Complex&lt;_Tp&gt;&amp; operator *= (Complex&lt;_Tp&gt;&amp; a, _Tp b)
<span class="lineNum">    1578 </span>            : { a.re *= b; a.im *= b; return a; }
<span class="lineNum">    1579 </span>            : 
<span class="lineNum">    1580 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1581 </span>            : double abs(const Complex&lt;_Tp&gt;&amp; a)
<span class="lineNum">    1582 </span>            : { return std::sqrt( (double)a.re*a.re + (double)a.im*a.im); }
<span class="lineNum">    1583 </span>            : 
<span class="lineNum">    1584 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1585 </span>            : Complex&lt;_Tp&gt; operator / (const Complex&lt;_Tp&gt;&amp; a, const Complex&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1586 </span>            : {
<span class="lineNum">    1587 </span>            :     double t = 1./((double)b.re*b.re + (double)b.im*b.im);
<span class="lineNum">    1588 </span>            :     return Complex&lt;_Tp&gt;( (_Tp)((a.re*b.re + a.im*b.im)*t),
<span class="lineNum">    1589 </span>            :                         (_Tp)((-a.re*b.im + a.im*b.re)*t) );
<span class="lineNum">    1590 </span>            : }
<span class="lineNum">    1591 </span>            : 
<span class="lineNum">    1592 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1593 </span>            : Complex&lt;_Tp&gt;&amp; operator /= (Complex&lt;_Tp&gt;&amp; a, const Complex&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1594 </span>            : {
<span class="lineNum">    1595 </span>            :     return (a = a / b);
<span class="lineNum">    1596 </span>            : }
<span class="lineNum">    1597 </span>            : 
<span class="lineNum">    1598 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1599 </span>            : Complex&lt;_Tp&gt; operator / (const Complex&lt;_Tp&gt;&amp; a, _Tp b)
<span class="lineNum">    1600 </span>            : {
<span class="lineNum">    1601 </span>            :     _Tp t = (_Tp)1/b;
<span class="lineNum">    1602 </span>            :     return Complex&lt;_Tp&gt;( a.re*t, a.im*t );
<span class="lineNum">    1603 </span>            : }
<span class="lineNum">    1604 </span>            : 
<span class="lineNum">    1605 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1606 </span>            : Complex&lt;_Tp&gt; operator / (_Tp b, const Complex&lt;_Tp&gt;&amp; a)
<span class="lineNum">    1607 </span>            : {
<span class="lineNum">    1608 </span>            :     return Complex&lt;_Tp&gt;(b)/a;
<span class="lineNum">    1609 </span>            : }
<span class="lineNum">    1610 </span>            : 
<span class="lineNum">    1611 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    1612 </span>            : Complex&lt;_Tp&gt; operator /= (const Complex&lt;_Tp&gt;&amp; a, _Tp b)
<span class="lineNum">    1613 </span>            : {
<span class="lineNum">    1614 </span>            :     _Tp t = (_Tp)1/b;
<span class="lineNum">    1615 </span>            :     a.re *= t; a.im *= t; return a;
<span class="lineNum">    1616 </span>            : }
<span class="lineNum">    1617 </span>            : 
<span class="lineNum">    1618 </span>            : //////////////////////////////// 2D Point ////////////////////////////////
<span class="lineNum">    1619 </span>            : 
<span class="lineNum">    1620 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt;::Point_() : x(0), y(0) {}
<span class="lineNum">    1621 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt;::Point_(_Tp _x, _Tp _y) : x(_x), y(_y) {}
<span class="lineNum">    1622 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt;::Point_(const Point_&amp; pt) : x(pt.x), y(pt.y) {}
<span class="lineNum">    1623 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt;::Point_(const CvPoint&amp; pt) : x((_Tp)pt.x), y((_Tp)pt.y) {}
<span class="lineNum">    1624 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt;::Point_(const CvPoint2D32f&amp; pt)
<span class="lineNum">    1625 </span>            :     : x(saturate_cast&lt;_Tp&gt;(pt.x)), y(saturate_cast&lt;_Tp&gt;(pt.y)) {}
<span class="lineNum">    1626 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt;::Point_(const Size_&lt;_Tp&gt;&amp; sz) : x(sz.width), y(sz.height) {}
<span class="lineNum">    1627 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt;::Point_(const Vec&lt;_Tp,2&gt;&amp; v) : x(v[0]), y(v[1]) {}
<span class="lineNum">    1628 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt;&amp; Point_&lt;_Tp&gt;::operator = (const Point_&amp; pt)
<span class="lineNum">    1629 </span>            : { x = pt.x; y = pt.y; return *this; }
<span class="lineNum">    1630 </span>            : 
<span class="lineNum">    1631 </span>            : template&lt;typename _Tp&gt; template&lt;typename _Tp2&gt; inline Point_&lt;_Tp&gt;::operator Point_&lt;_Tp2&gt;() const
<span class="lineNum">    1632 </span>            : { return Point_&lt;_Tp2&gt;(saturate_cast&lt;_Tp2&gt;(x), saturate_cast&lt;_Tp2&gt;(y)); }
<span class="lineNum">    1633 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt;::operator CvPoint() const
<span class="lineNum">    1634 </span>            : { return cvPoint(saturate_cast&lt;int&gt;(x), saturate_cast&lt;int&gt;(y)); }
<span class="lineNum">    1635 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt;::operator CvPoint2D32f() const
<span class="lineNum">    1636 </span>            : { return cvPoint2D32f((float)x, (float)y); }
<span class="lineNum">    1637 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt;::operator Vec&lt;_Tp, 2&gt;() const
<span class="lineNum">    1638 </span>            : { return Vec&lt;_Tp, 2&gt;(x, y); }
<span class="lineNum">    1639 </span>            : 
<span class="lineNum">    1640 </span>            : template&lt;typename _Tp&gt; inline _Tp Point_&lt;_Tp&gt;::dot(const Point_&amp; pt) const
<span class="lineNum">    1641 </span>            : { return saturate_cast&lt;_Tp&gt;(x*pt.x + y*pt.y); }
<span class="lineNum">    1642 </span>            : template&lt;typename _Tp&gt; inline double Point_&lt;_Tp&gt;::ddot(const Point_&amp; pt) const
<span class="lineNum">    1643 </span>            : { return (double)x*pt.x + (double)y*pt.y; }
<span class="lineNum">    1644 </span>            : 
<span class="lineNum">    1645 </span>            : template&lt;typename _Tp&gt; inline double Point_&lt;_Tp&gt;::cross(const Point_&amp; pt) const
<span class="lineNum">    1646 </span>            : { return (double)x*pt.y - (double)y*pt.x; }
<span class="lineNum">    1647 </span>            : 
<span class="lineNum">    1648 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt;&amp;
<span class="lineNum">    1649 </span>            : operator += (Point_&lt;_Tp&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1650 </span>            : {
<span class="lineNum">    1651 </span>            :     a.x = saturate_cast&lt;_Tp&gt;(a.x + b.x);
<span class="lineNum">    1652 </span>            :     a.y = saturate_cast&lt;_Tp&gt;(a.y + b.y);
<span class="lineNum">    1653 </span>            :     return a;
<span class="lineNum">    1654 </span>            : }
<span class="lineNum">    1655 </span>            : 
<span class="lineNum">    1656 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt;&amp;
<span class="lineNum">    1657 </span>            : operator -= (Point_&lt;_Tp&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1658 </span>            : {
<span class="lineNum">    1659 </span>            :     a.x = saturate_cast&lt;_Tp&gt;(a.x - b.x);
<span class="lineNum">    1660 </span>            :     a.y = saturate_cast&lt;_Tp&gt;(a.y - b.y);
<span class="lineNum">    1661 </span>            :     return a;
<span class="lineNum">    1662 </span>            : }
<span class="lineNum">    1663 </span>            : 
<span class="lineNum">    1664 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt;&amp;
<span class="lineNum">    1665 </span>            : operator *= (Point_&lt;_Tp&gt;&amp; a, int b)
<span class="lineNum">    1666 </span>            : {
<span class="lineNum">    1667 </span>            :     a.x = saturate_cast&lt;_Tp&gt;(a.x*b);
<span class="lineNum">    1668 </span>            :     a.y = saturate_cast&lt;_Tp&gt;(a.y*b);
<span class="lineNum">    1669 </span>            :     return a;
<span class="lineNum">    1670 </span>            : }
<span class="lineNum">    1671 </span>            : 
<span class="lineNum">    1672 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt;&amp;
<span class="lineNum">    1673 </span>            : operator *= (Point_&lt;_Tp&gt;&amp; a, float b)
<span class="lineNum">    1674 </span>            : {
<span class="lineNum">    1675 </span>            :     a.x = saturate_cast&lt;_Tp&gt;(a.x*b);
<span class="lineNum">    1676 </span>            :     a.y = saturate_cast&lt;_Tp&gt;(a.y*b);
<span class="lineNum">    1677 </span>            :     return a;
<span class="lineNum">    1678 </span>            : }
<span class="lineNum">    1679 </span>            : 
<span class="lineNum">    1680 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt;&amp;
<span class="lineNum">    1681 </span>            : operator *= (Point_&lt;_Tp&gt;&amp; a, double b)
<span class="lineNum">    1682 </span>            : {
<span class="lineNum">    1683 </span>            :     a.x = saturate_cast&lt;_Tp&gt;(a.x*b);
<span class="lineNum">    1684 </span>            :     a.y = saturate_cast&lt;_Tp&gt;(a.y*b);
<span class="lineNum">    1685 </span>            :     return a;
<span class="lineNum">    1686 </span>            : }
<span class="lineNum">    1687 </span>            : 
<span class="lineNum">    1688 </span>            : template&lt;typename _Tp&gt; static inline double norm(const Point_&lt;_Tp&gt;&amp; pt)
<span class="lineNum">    1689 </span>            : { return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y); }
<span class="lineNum">    1690 </span>            : 
<span class="lineNum">    1691 </span>            : template&lt;typename _Tp&gt; static inline bool operator == (const Point_&lt;_Tp&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1692 </span>            : { return a.x == b.x &amp;&amp; a.y == b.y; }
<span class="lineNum">    1693 </span>            : 
<span class="lineNum">    1694 </span>            : template&lt;typename _Tp&gt; static inline bool operator != (const Point_&lt;_Tp&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1695 </span>            : { return a.x != b.x || a.y != b.y; }
<span class="lineNum">    1696 </span>            : 
<span class="lineNum">    1697 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt; operator + (const Point_&lt;_Tp&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1698 </span>            : { return Point_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(a.x + b.x), saturate_cast&lt;_Tp&gt;(a.y + b.y) ); }
<span class="lineNum">    1699 </span>            : 
<span class="lineNum">    1700 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt; operator - (const Point_&lt;_Tp&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1701 </span>            : { return Point_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(a.x - b.x), saturate_cast&lt;_Tp&gt;(a.y - b.y) ); }
<span class="lineNum">    1702 </span>            : 
<span class="lineNum">    1703 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt; operator - (const Point_&lt;_Tp&gt;&amp; a)
<span class="lineNum">    1704 </span>            : { return Point_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(-a.x), saturate_cast&lt;_Tp&gt;(-a.y) ); }
<span class="lineNum">    1705 </span>            : 
<span class="lineNum">    1706 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt; operator * (const Point_&lt;_Tp&gt;&amp; a, int b)
<span class="lineNum">    1707 </span>            : { return Point_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(a.x*b), saturate_cast&lt;_Tp&gt;(a.y*b) ); }
<span class="lineNum">    1708 </span>            : 
<span class="lineNum">    1709 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt; operator * (int a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1710 </span>            : { return Point_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(b.x*a), saturate_cast&lt;_Tp&gt;(b.y*a) ); }
<span class="lineNum">    1711 </span>            : 
<span class="lineNum">    1712 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt; operator * (const Point_&lt;_Tp&gt;&amp; a, float b)
<span class="lineNum">    1713 </span>            : { return Point_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(a.x*b), saturate_cast&lt;_Tp&gt;(a.y*b) ); }
<span class="lineNum">    1714 </span>            : 
<span class="lineNum">    1715 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt; operator * (float a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1716 </span>            : { return Point_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(b.x*a), saturate_cast&lt;_Tp&gt;(b.y*a) ); }
<span class="lineNum">    1717 </span>            : 
<span class="lineNum">    1718 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt; operator * (const Point_&lt;_Tp&gt;&amp; a, double b)
<span class="lineNum">    1719 </span>            : { return Point_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(a.x*b), saturate_cast&lt;_Tp&gt;(a.y*b) ); }
<span class="lineNum">    1720 </span>            : 
<span class="lineNum">    1721 </span>            : template&lt;typename _Tp&gt; static inline Point_&lt;_Tp&gt; operator * (double a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1722 </span>            : { return Point_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(b.x*a), saturate_cast&lt;_Tp&gt;(b.y*a) ); }
<span class="lineNum">    1723 </span>            : 
<span class="lineNum">    1724 </span>            : //////////////////////////////// 3D Point ////////////////////////////////
<span class="lineNum">    1725 </span>            : 
<span class="lineNum">    1726 </span>            : template&lt;typename _Tp&gt; inline Point3_&lt;_Tp&gt;::Point3_() : x(0), y(0), z(0) {}
<span class="lineNum">    1727 </span>            : template&lt;typename _Tp&gt; inline Point3_&lt;_Tp&gt;::Point3_(_Tp _x, _Tp _y, _Tp _z) : x(_x), y(_y), z(_z) {}
<span class="lineNum">    1728 </span>            : template&lt;typename _Tp&gt; inline Point3_&lt;_Tp&gt;::Point3_(const Point3_&amp; pt) : x(pt.x), y(pt.y), z(pt.z) {}
<span class="lineNum">    1729 </span>            : template&lt;typename _Tp&gt; inline Point3_&lt;_Tp&gt;::Point3_(const Point_&lt;_Tp&gt;&amp; pt) : x(pt.x), y(pt.y), z(_Tp()) {}
<span class="lineNum">    1730 </span>            : template&lt;typename _Tp&gt; inline Point3_&lt;_Tp&gt;::Point3_(const CvPoint3D32f&amp; pt) :
<span class="lineNum">    1731 </span>            :     x(saturate_cast&lt;_Tp&gt;(pt.x)), y(saturate_cast&lt;_Tp&gt;(pt.y)), z(saturate_cast&lt;_Tp&gt;(pt.z)) {}
<span class="lineNum">    1732 </span>            : template&lt;typename _Tp&gt; inline Point3_&lt;_Tp&gt;::Point3_(const Vec&lt;_Tp, 3&gt;&amp; v) : x(v[0]), y(v[1]), z(v[2]) {}
<span class="lineNum">    1733 </span>            : 
<span class="lineNum">    1734 </span>            : template&lt;typename _Tp&gt; template&lt;typename _Tp2&gt; inline Point3_&lt;_Tp&gt;::operator Point3_&lt;_Tp2&gt;() const
<span class="lineNum">    1735 </span>            : { return Point3_&lt;_Tp2&gt;(saturate_cast&lt;_Tp2&gt;(x), saturate_cast&lt;_Tp2&gt;(y), saturate_cast&lt;_Tp2&gt;(z)); }
<span class="lineNum">    1736 </span>            : 
<span class="lineNum">    1737 </span>            : template&lt;typename _Tp&gt; inline Point3_&lt;_Tp&gt;::operator CvPoint3D32f() const
<span class="lineNum">    1738 </span>            : { return cvPoint3D32f((float)x, (float)y, (float)z); }
<span class="lineNum">    1739 </span>            : 
<span class="lineNum">    1740 </span>            : template&lt;typename _Tp&gt; inline Point3_&lt;_Tp&gt;::operator Vec&lt;_Tp, 3&gt;() const
<span class="lineNum">    1741 </span>            : { return Vec&lt;_Tp, 3&gt;(x, y, z); }
<span class="lineNum">    1742 </span>            : 
<span class="lineNum">    1743 </span>            : template&lt;typename _Tp&gt; inline Point3_&lt;_Tp&gt;&amp; Point3_&lt;_Tp&gt;::operator = (const Point3_&amp; pt)
<span class="lineNum">    1744 </span>            : { x = pt.x; y = pt.y; z = pt.z; return *this; }
<span class="lineNum">    1745 </span>            : 
<span class="lineNum">    1746 </span>            : template&lt;typename _Tp&gt; inline _Tp Point3_&lt;_Tp&gt;::dot(const Point3_&amp; pt) const
<span class="lineNum">    1747 </span>            : { return saturate_cast&lt;_Tp&gt;(x*pt.x + y*pt.y + z*pt.z); }
<span class="lineNum">    1748 </span>            : template&lt;typename _Tp&gt; inline double Point3_&lt;_Tp&gt;::ddot(const Point3_&amp; pt) const
<span class="lineNum">    1749 </span>            : { return (double)x*pt.x + (double)y*pt.y + (double)z*pt.z; }
<span class="lineNum">    1750 </span>            : 
<span class="lineNum">    1751 </span>            : template&lt;typename _Tp&gt; inline Point3_&lt;_Tp&gt; Point3_&lt;_Tp&gt;::cross(const Point3_&lt;_Tp&gt;&amp; pt) const
<span class="lineNum">    1752 </span>            : {
<span class="lineNum">    1753 </span>            :     return Point3_&lt;_Tp&gt;(y*pt.z - z*pt.y, z*pt.x - x*pt.z, x*pt.y - y*pt.x);
<span class="lineNum">    1754 </span>            : }
<span class="lineNum">    1755 </span>            : 
<span class="lineNum">    1756 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt;&amp;
<span class="lineNum">    1757 </span>            : operator += (Point3_&lt;_Tp&gt;&amp; a, const Point3_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1758 </span>            : {
<span class="lineNum">    1759 </span>            :     a.x = saturate_cast&lt;_Tp&gt;(a.x + b.x);
<span class="lineNum">    1760 </span>            :     a.y = saturate_cast&lt;_Tp&gt;(a.y + b.y);
<span class="lineNum">    1761 </span>            :     a.z = saturate_cast&lt;_Tp&gt;(a.z + b.z);
<span class="lineNum">    1762 </span>            :     return a;
<span class="lineNum">    1763 </span>            : }
<span class="lineNum">    1764 </span>            : 
<span class="lineNum">    1765 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt;&amp;
<span class="lineNum">    1766 </span>            : operator -= (Point3_&lt;_Tp&gt;&amp; a, const Point3_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1767 </span>            : {
<span class="lineNum">    1768 </span>            :     a.x = saturate_cast&lt;_Tp&gt;(a.x - b.x);
<span class="lineNum">    1769 </span>            :     a.y = saturate_cast&lt;_Tp&gt;(a.y - b.y);
<span class="lineNum">    1770 </span>            :     a.z = saturate_cast&lt;_Tp&gt;(a.z - b.z);
<span class="lineNum">    1771 </span>            :     return a;
<span class="lineNum">    1772 </span>            : }
<span class="lineNum">    1773 </span>            : 
<span class="lineNum">    1774 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt;&amp;
<span class="lineNum">    1775 </span>            : operator *= (Point3_&lt;_Tp&gt;&amp; a, int b)
<span class="lineNum">    1776 </span>            : {
<span class="lineNum">    1777 </span>            :     a.x = saturate_cast&lt;_Tp&gt;(a.x*b);
<span class="lineNum">    1778 </span>            :     a.y = saturate_cast&lt;_Tp&gt;(a.y*b);
<span class="lineNum">    1779 </span>            :     a.z = saturate_cast&lt;_Tp&gt;(a.z*b);
<span class="lineNum">    1780 </span>            :     return a;
<span class="lineNum">    1781 </span>            : }
<span class="lineNum">    1782 </span>            : 
<span class="lineNum">    1783 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt;&amp;
<span class="lineNum">    1784 </span>            : operator *= (Point3_&lt;_Tp&gt;&amp; a, float b)
<span class="lineNum">    1785 </span>            : {
<span class="lineNum">    1786 </span>            :     a.x = saturate_cast&lt;_Tp&gt;(a.x*b);
<span class="lineNum">    1787 </span>            :     a.y = saturate_cast&lt;_Tp&gt;(a.y*b);
<span class="lineNum">    1788 </span>            :     a.z = saturate_cast&lt;_Tp&gt;(a.z*b);
<span class="lineNum">    1789 </span>            :     return a;
<span class="lineNum">    1790 </span>            : }
<span class="lineNum">    1791 </span>            : 
<span class="lineNum">    1792 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt;&amp;
<span class="lineNum">    1793 </span>            : operator *= (Point3_&lt;_Tp&gt;&amp; a, double b)
<span class="lineNum">    1794 </span>            : {
<span class="lineNum">    1795 </span>            :     a.x = saturate_cast&lt;_Tp&gt;(a.x*b);
<span class="lineNum">    1796 </span>            :     a.y = saturate_cast&lt;_Tp&gt;(a.y*b);
<span class="lineNum">    1797 </span>            :     a.z = saturate_cast&lt;_Tp&gt;(a.z*b);
<span class="lineNum">    1798 </span>            :     return a;
<span class="lineNum">    1799 </span>            : }
<span class="lineNum">    1800 </span>            : 
<span class="lineNum">    1801 </span>            : template&lt;typename _Tp&gt; static inline double norm(const Point3_&lt;_Tp&gt;&amp; pt)
<span class="lineNum">    1802 </span>            : { return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y + (double)pt.z*pt.z); }
<span class="lineNum">    1803 </span>            : 
<span class="lineNum">    1804 </span>            : template&lt;typename _Tp&gt; static inline bool operator == (const Point3_&lt;_Tp&gt;&amp; a, const Point3_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1805 </span>            : { return a.x == b.x &amp;&amp; a.y == b.y &amp;&amp; a.z == b.z; }
<span class="lineNum">    1806 </span>            : 
<span class="lineNum">    1807 </span>            : template&lt;typename _Tp&gt; static inline bool operator != (const Point3_&lt;_Tp&gt;&amp; a, const Point3_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1808 </span>            : { return a.x != b.x || a.y != b.y || a.z != b.z; }
<span class="lineNum">    1809 </span>            : 
<span class="lineNum">    1810 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt; operator + (const Point3_&lt;_Tp&gt;&amp; a, const Point3_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1811 </span>            : { return Point3_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(a.x + b.x),
<span class="lineNum">    1812 </span>            :                       saturate_cast&lt;_Tp&gt;(a.y + b.y),
<span class="lineNum">    1813 </span>            :                       saturate_cast&lt;_Tp&gt;(a.z + b.z)); }
<span class="lineNum">    1814 </span>            : 
<span class="lineNum">    1815 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt; operator - (const Point3_&lt;_Tp&gt;&amp; a, const Point3_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1816 </span>            : { return Point3_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(a.x - b.x),
<span class="lineNum">    1817 </span>            :                         saturate_cast&lt;_Tp&gt;(a.y - b.y),
<span class="lineNum">    1818 </span>            :                         saturate_cast&lt;_Tp&gt;(a.z - b.z)); }
<span class="lineNum">    1819 </span>            : 
<span class="lineNum">    1820 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt; operator - (const Point3_&lt;_Tp&gt;&amp; a)
<span class="lineNum">    1821 </span>            : { return Point3_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(-a.x),
<span class="lineNum">    1822 </span>            :                       saturate_cast&lt;_Tp&gt;(-a.y),
<span class="lineNum">    1823 </span>            :                       saturate_cast&lt;_Tp&gt;(-a.z) ); }
<span class="lineNum">    1824 </span>            : 
<span class="lineNum">    1825 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt; operator * (const Point3_&lt;_Tp&gt;&amp; a, int b)
<span class="lineNum">    1826 </span>            : { return Point3_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(a.x*b),
<span class="lineNum">    1827 </span>            :                       saturate_cast&lt;_Tp&gt;(a.y*b),
<span class="lineNum">    1828 </span>            :                       saturate_cast&lt;_Tp&gt;(a.z*b) ); }
<span class="lineNum">    1829 </span>            : 
<span class="lineNum">    1830 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt; operator * (int a, const Point3_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1831 </span>            : { return Point3_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(b.x*a),
<span class="lineNum">    1832 </span>            :                       saturate_cast&lt;_Tp&gt;(b.y*a),
<span class="lineNum">    1833 </span>            :                       saturate_cast&lt;_Tp&gt;(b.z*a) ); }
<span class="lineNum">    1834 </span>            : 
<span class="lineNum">    1835 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt; operator * (const Point3_&lt;_Tp&gt;&amp; a, float b)
<span class="lineNum">    1836 </span>            : { return Point3_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(a.x*b),
<span class="lineNum">    1837 </span>            :                       saturate_cast&lt;_Tp&gt;(a.y*b),
<span class="lineNum">    1838 </span>            :                       saturate_cast&lt;_Tp&gt;(a.z*b) ); }
<span class="lineNum">    1839 </span>            : 
<span class="lineNum">    1840 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt; operator * (float a, const Point3_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1841 </span>            : { return Point3_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(b.x*a),
<span class="lineNum">    1842 </span>            :                       saturate_cast&lt;_Tp&gt;(b.y*a),
<span class="lineNum">    1843 </span>            :                       saturate_cast&lt;_Tp&gt;(b.z*a) ); }
<span class="lineNum">    1844 </span>            : 
<span class="lineNum">    1845 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt; operator * (const Point3_&lt;_Tp&gt;&amp; a, double b)
<span class="lineNum">    1846 </span>            : { return Point3_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(a.x*b),
<span class="lineNum">    1847 </span>            :                       saturate_cast&lt;_Tp&gt;(a.y*b),
<span class="lineNum">    1848 </span>            :                       saturate_cast&lt;_Tp&gt;(a.z*b) ); }
<span class="lineNum">    1849 </span>            : 
<span class="lineNum">    1850 </span>            : template&lt;typename _Tp&gt; static inline Point3_&lt;_Tp&gt; operator * (double a, const Point3_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1851 </span>            : { return Point3_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(b.x*a),
<span class="lineNum">    1852 </span>            :                       saturate_cast&lt;_Tp&gt;(b.y*a),
<span class="lineNum">    1853 </span>            :                       saturate_cast&lt;_Tp&gt;(b.z*a) ); }
<span class="lineNum">    1854 </span>            : 
<span class="lineNum">    1855 </span>            : //////////////////////////////// Size ////////////////////////////////
<span class="lineNum">    1856 </span>            : 
<span class="lineNum">    1857 </span>            : template&lt;typename _Tp&gt; inline Size_&lt;_Tp&gt;::Size_()
<span class="lineNum">    1858 </span><span class="lineNoCov">          0 :     : width(0), height(0) {}</span>
<span class="lineNum">    1859 </span>            : template&lt;typename _Tp&gt; inline Size_&lt;_Tp&gt;::Size_(_Tp _width, _Tp _height)
<span class="lineNum">    1860 </span><span class="lineNoCov">          0 :     : width(_width), height(_height) {}</span>
<span class="lineNum">    1861 </span>            : template&lt;typename _Tp&gt; inline Size_&lt;_Tp&gt;::Size_(const Size_&amp; sz)
<span class="lineNum">    1862 </span><span class="lineNoCov">          0 :     : width(sz.width), height(sz.height) {}</span>
<span class="lineNum">    1863 </span>            : template&lt;typename _Tp&gt; inline Size_&lt;_Tp&gt;::Size_(const CvSize&amp; sz)
<span class="lineNum">    1864 </span>            :     : width(saturate_cast&lt;_Tp&gt;(sz.width)), height(saturate_cast&lt;_Tp&gt;(sz.height)) {}
<span class="lineNum">    1865 </span>            : template&lt;typename _Tp&gt; inline Size_&lt;_Tp&gt;::Size_(const CvSize2D32f&amp; sz)
<span class="lineNum">    1866 </span>            :     : width(saturate_cast&lt;_Tp&gt;(sz.width)), height(saturate_cast&lt;_Tp&gt;(sz.height)) {}
<span class="lineNum">    1867 </span>            : template&lt;typename _Tp&gt; inline Size_&lt;_Tp&gt;::Size_(const Point_&lt;_Tp&gt;&amp; pt) : width(pt.x), height(pt.y) {}
<span class="lineNum">    1868 </span>            : 
<span class="lineNum">    1869 </span>            : template&lt;typename _Tp&gt; template&lt;typename _Tp2&gt; inline Size_&lt;_Tp&gt;::operator Size_&lt;_Tp2&gt;() const
<span class="lineNum">    1870 </span>            : { return Size_&lt;_Tp2&gt;(saturate_cast&lt;_Tp2&gt;(width), saturate_cast&lt;_Tp2&gt;(height)); }
<span class="lineNum">    1871 </span>            : template&lt;typename _Tp&gt; inline Size_&lt;_Tp&gt;::operator CvSize() const
<span class="lineNum">    1872 </span>            : { return cvSize(saturate_cast&lt;int&gt;(width), saturate_cast&lt;int&gt;(height)); }
<span class="lineNum">    1873 </span>            : template&lt;typename _Tp&gt; inline Size_&lt;_Tp&gt;::operator CvSize2D32f() const
<span class="lineNum">    1874 </span>            : { return cvSize2D32f((float)width, (float)height); }
<span class="lineNum">    1875 </span>            : 
<span class="lineNum">    1876 </span>            : template&lt;typename _Tp&gt; inline Size_&lt;_Tp&gt;&amp; Size_&lt;_Tp&gt;::operator = (const Size_&lt;_Tp&gt;&amp; sz)
<span class="lineNum">    1877 </span>            : { width = sz.width; height = sz.height; return *this; }
<span class="lineNum">    1878 </span>            : template&lt;typename _Tp&gt; static inline Size_&lt;_Tp&gt; operator * (const Size_&lt;_Tp&gt;&amp; a, _Tp b)
<span class="lineNum">    1879 </span>            : { return Size_&lt;_Tp&gt;(a.width * b, a.height * b); }
<span class="lineNum">    1880 </span>            : template&lt;typename _Tp&gt; static inline Size_&lt;_Tp&gt; operator + (const Size_&lt;_Tp&gt;&amp; a, const Size_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1881 </span>            : { return Size_&lt;_Tp&gt;(a.width + b.width, a.height + b.height); }
<span class="lineNum">    1882 </span>            : template&lt;typename _Tp&gt; static inline Size_&lt;_Tp&gt; operator - (const Size_&lt;_Tp&gt;&amp; a, const Size_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1883 </span>            : { return Size_&lt;_Tp&gt;(a.width - b.width, a.height - b.height); }
<span class="lineNum">    1884 </span>            : template&lt;typename _Tp&gt; inline _Tp Size_&lt;_Tp&gt;::area() const { return width*height; }
<span class="lineNum">    1885 </span>            : 
<span class="lineNum">    1886 </span>            : template&lt;typename _Tp&gt; static inline Size_&lt;_Tp&gt;&amp; operator += (Size_&lt;_Tp&gt;&amp; a, const Size_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1887 </span>            : { a.width += b.width; a.height += b.height; return a; }
<span class="lineNum">    1888 </span>            : template&lt;typename _Tp&gt; static inline Size_&lt;_Tp&gt;&amp; operator -= (Size_&lt;_Tp&gt;&amp; a, const Size_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1889 </span>            : { a.width -= b.width; a.height -= b.height; return a; }
<span class="lineNum">    1890 </span>            : 
<span class="lineNum">    1891 </span>            : template&lt;typename _Tp&gt; static inline bool operator == (const Size_&lt;_Tp&gt;&amp; a, const Size_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1892 </span>            : { return a.width == b.width &amp;&amp; a.height == b.height; }
<span class="lineNum">    1893 </span>            : template&lt;typename _Tp&gt; static inline bool operator != (const Size_&lt;_Tp&gt;&amp; a, const Size_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1894 </span>            : { return a.width != b.width || a.height != b.height; }
<span class="lineNum">    1895 </span>            : 
<span class="lineNum">    1896 </span>            : //////////////////////////////// Rect ////////////////////////////////
<span class="lineNum">    1897 </span>            : 
<span class="lineNum">    1898 </span>            : 
<span class="lineNum">    1899 </span>            : template&lt;typename _Tp&gt; inline Rect_&lt;_Tp&gt;::Rect_() : x(0), y(0), width(0), height(0) {}
<span class="lineNum">    1900 </span><span class="lineNoCov">          0 : template&lt;typename _Tp&gt; inline Rect_&lt;_Tp&gt;::Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height) : x(_x), y(_y), width(_width), height(_height) {}</span>
<span class="lineNum">    1901 </span>            : template&lt;typename _Tp&gt; inline Rect_&lt;_Tp&gt;::Rect_(const Rect_&lt;_Tp&gt;&amp; r) : x(r.x), y(r.y), width(r.width), height(r.height) {}
<span class="lineNum">    1902 </span>            : template&lt;typename _Tp&gt; inline Rect_&lt;_Tp&gt;::Rect_(const CvRect&amp; r) : x((_Tp)r.x), y((_Tp)r.y), width((_Tp)r.width), height((_Tp)r.height) {}
<span class="lineNum">    1903 </span>            : template&lt;typename _Tp&gt; inline Rect_&lt;_Tp&gt;::Rect_(const Point_&lt;_Tp&gt;&amp; org, const Size_&lt;_Tp&gt;&amp; sz) :
<span class="lineNum">    1904 </span>            :     x(org.x), y(org.y), width(sz.width), height(sz.height) {}
<span class="lineNum">    1905 </span>            : template&lt;typename _Tp&gt; inline Rect_&lt;_Tp&gt;::Rect_(const Point_&lt;_Tp&gt;&amp; pt1, const Point_&lt;_Tp&gt;&amp; pt2)
<span class="lineNum">    1906 </span>            : {
<span class="lineNum">    1907 </span>            :     x = std::min(pt1.x, pt2.x); y = std::min(pt1.y, pt2.y);
<span class="lineNum">    1908 </span>            :     width = std::max(pt1.x, pt2.x) - x; height = std::max(pt1.y, pt2.y) - y;
<span class="lineNum">    1909 </span>            : }
<span class="lineNum">    1910 </span>            : template&lt;typename _Tp&gt; inline Rect_&lt;_Tp&gt;&amp; Rect_&lt;_Tp&gt;::operator = ( const Rect_&lt;_Tp&gt;&amp; r )
<span class="lineNum">    1911 </span>            : { x = r.x; y = r.y; width = r.width; height = r.height; return *this; }
<span class="lineNum">    1912 </span>            : 
<span class="lineNum">    1913 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt; Rect_&lt;_Tp&gt;::tl() const { return Point_&lt;_Tp&gt;(x,y); }
<span class="lineNum">    1914 </span>            : template&lt;typename _Tp&gt; inline Point_&lt;_Tp&gt; Rect_&lt;_Tp&gt;::br() const { return Point_&lt;_Tp&gt;(x+width, y+height); }
<span class="lineNum">    1915 </span>            : 
<span class="lineNum">    1916 </span>            : template&lt;typename _Tp&gt; static inline Rect_&lt;_Tp&gt;&amp; operator += ( Rect_&lt;_Tp&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b )
<span class="lineNum">    1917 </span>            : { a.x += b.x; a.y += b.y; return a; }
<span class="lineNum">    1918 </span>            : template&lt;typename _Tp&gt; static inline Rect_&lt;_Tp&gt;&amp; operator -= ( Rect_&lt;_Tp&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b )
<span class="lineNum">    1919 </span>            : { a.x -= b.x; a.y -= b.y; return a; }
<span class="lineNum">    1920 </span>            : 
<span class="lineNum">    1921 </span>            : template&lt;typename _Tp&gt; static inline Rect_&lt;_Tp&gt;&amp; operator += ( Rect_&lt;_Tp&gt;&amp; a, const Size_&lt;_Tp&gt;&amp; b )
<span class="lineNum">    1922 </span>            : { a.width += b.width; a.height += b.height; return a; }
<span class="lineNum">    1923 </span>            : 
<span class="lineNum">    1924 </span>            : template&lt;typename _Tp&gt; static inline Rect_&lt;_Tp&gt;&amp; operator -= ( Rect_&lt;_Tp&gt;&amp; a, const Size_&lt;_Tp&gt;&amp; b )
<span class="lineNum">    1925 </span>            : { a.width -= b.width; a.height -= b.height; return a; }
<span class="lineNum">    1926 </span>            : 
<span class="lineNum">    1927 </span>            : template&lt;typename _Tp&gt; static inline Rect_&lt;_Tp&gt;&amp; operator &amp;= ( Rect_&lt;_Tp&gt;&amp; a, const Rect_&lt;_Tp&gt;&amp; b )
<span class="lineNum">    1928 </span>            : {
<span class="lineNum">    1929 </span>            :     _Tp x1 = std::max(a.x, b.x), y1 = std::max(a.y, b.y);
<span class="lineNum">    1930 </span>            :     a.width = std::min(a.x + a.width, b.x + b.width) - x1;
<span class="lineNum">    1931 </span>            :     a.height = std::min(a.y + a.height, b.y + b.height) - y1;
<span class="lineNum">    1932 </span>            :     a.x = x1; a.y = y1;
<span class="lineNum">    1933 </span>            :     if( a.width &lt;= 0 || a.height &lt;= 0 )
<span class="lineNum">    1934 </span>            :         a = Rect();
<span class="lineNum">    1935 </span>            :     return a;
<span class="lineNum">    1936 </span>            : }
<span class="lineNum">    1937 </span>            : 
<span class="lineNum">    1938 </span>            : template&lt;typename _Tp&gt; static inline Rect_&lt;_Tp&gt;&amp; operator |= ( Rect_&lt;_Tp&gt;&amp; a, const Rect_&lt;_Tp&gt;&amp; b )
<span class="lineNum">    1939 </span>            : {
<span class="lineNum">    1940 </span>            :     _Tp x1 = std::min(a.x, b.x), y1 = std::min(a.y, b.y);
<span class="lineNum">    1941 </span>            :     a.width = std::max(a.x + a.width, b.x + b.width) - x1;
<span class="lineNum">    1942 </span>            :     a.height = std::max(a.y + a.height, b.y + b.height) - y1;
<span class="lineNum">    1943 </span>            :     a.x = x1; a.y = y1;
<span class="lineNum">    1944 </span>            :     return a;
<span class="lineNum">    1945 </span>            : }
<span class="lineNum">    1946 </span>            : 
<span class="lineNum">    1947 </span>            : template&lt;typename _Tp&gt; inline Size_&lt;_Tp&gt; Rect_&lt;_Tp&gt;::size() const { return Size_&lt;_Tp&gt;(width, height); }
<span class="lineNum">    1948 </span>            : template&lt;typename _Tp&gt; inline _Tp Rect_&lt;_Tp&gt;::area() const { return width*height; }
<span class="lineNum">    1949 </span>            : 
<span class="lineNum">    1950 </span>            : template&lt;typename _Tp&gt; template&lt;typename _Tp2&gt; inline Rect_&lt;_Tp&gt;::operator Rect_&lt;_Tp2&gt;() const
<span class="lineNum">    1951 </span>            : { return Rect_&lt;_Tp2&gt;(saturate_cast&lt;_Tp2&gt;(x), saturate_cast&lt;_Tp2&gt;(y),
<span class="lineNum">    1952 </span>            :                      saturate_cast&lt;_Tp2&gt;(width), saturate_cast&lt;_Tp2&gt;(height)); }
<span class="lineNum">    1953 </span>            : template&lt;typename _Tp&gt; inline Rect_&lt;_Tp&gt;::operator CvRect() const
<span class="lineNum">    1954 </span>            : { return cvRect(saturate_cast&lt;int&gt;(x), saturate_cast&lt;int&gt;(y),
<span class="lineNum">    1955 </span>            :                 saturate_cast&lt;int&gt;(width), saturate_cast&lt;int&gt;(height)); }
<span class="lineNum">    1956 </span>            : 
<span class="lineNum">    1957 </span>            : template&lt;typename _Tp&gt; inline bool Rect_&lt;_Tp&gt;::contains(const Point_&lt;_Tp&gt;&amp; pt) const
<span class="lineNum">    1958 </span>            : { return x &lt;= pt.x &amp;&amp; pt.x &lt; x + width &amp;&amp; y &lt;= pt.y &amp;&amp; pt.y &lt; y + height; }
<span class="lineNum">    1959 </span>            : 
<span class="lineNum">    1960 </span>            : template&lt;typename _Tp&gt; static inline bool operator == (const Rect_&lt;_Tp&gt;&amp; a, const Rect_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1961 </span>            : {
<span class="lineNum">    1962 </span>            :     return a.x == b.x &amp;&amp; a.y == b.y &amp;&amp; a.width == b.width &amp;&amp; a.height == b.height;
<span class="lineNum">    1963 </span>            : }
<span class="lineNum">    1964 </span>            : 
<span class="lineNum">    1965 </span>            : template&lt;typename _Tp&gt; static inline bool operator != (const Rect_&lt;_Tp&gt;&amp; a, const Rect_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1966 </span>            : {
<span class="lineNum">    1967 </span>            :     return a.x != b.x || a.y != b.y || a.width != b.width || a.height != b.height;
<span class="lineNum">    1968 </span>            : }
<span class="lineNum">    1969 </span>            : 
<span class="lineNum">    1970 </span>            : template&lt;typename _Tp&gt; static inline Rect_&lt;_Tp&gt; operator + (const Rect_&lt;_Tp&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1971 </span>            : {
<span class="lineNum">    1972 </span>            :     return Rect_&lt;_Tp&gt;( a.x + b.x, a.y + b.y, a.width, a.height );
<span class="lineNum">    1973 </span>            : }
<span class="lineNum">    1974 </span>            : 
<span class="lineNum">    1975 </span>            : template&lt;typename _Tp&gt; static inline Rect_&lt;_Tp&gt; operator - (const Rect_&lt;_Tp&gt;&amp; a, const Point_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1976 </span>            : {
<span class="lineNum">    1977 </span>            :     return Rect_&lt;_Tp&gt;( a.x - b.x, a.y - b.y, a.width, a.height );
<span class="lineNum">    1978 </span>            : }
<span class="lineNum">    1979 </span>            : 
<span class="lineNum">    1980 </span>            : template&lt;typename _Tp&gt; static inline Rect_&lt;_Tp&gt; operator + (const Rect_&lt;_Tp&gt;&amp; a, const Size_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1981 </span>            : {
<span class="lineNum">    1982 </span>            :     return Rect_&lt;_Tp&gt;( a.x, a.y, a.width + b.width, a.height + b.height );
<span class="lineNum">    1983 </span>            : }
<span class="lineNum">    1984 </span>            : 
<span class="lineNum">    1985 </span>            : template&lt;typename _Tp&gt; static inline Rect_&lt;_Tp&gt; operator &amp; (const Rect_&lt;_Tp&gt;&amp; a, const Rect_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1986 </span>            : {
<span class="lineNum">    1987 </span>            :     Rect_&lt;_Tp&gt; c = a;
<span class="lineNum">    1988 </span>            :     return c &amp;= b;
<span class="lineNum">    1989 </span>            : }
<span class="lineNum">    1990 </span>            : 
<span class="lineNum">    1991 </span>            : template&lt;typename _Tp&gt; static inline Rect_&lt;_Tp&gt; operator | (const Rect_&lt;_Tp&gt;&amp; a, const Rect_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    1992 </span>            : {
<span class="lineNum">    1993 </span>            :     Rect_&lt;_Tp&gt; c = a;
<span class="lineNum">    1994 </span>            :     return c |= b;
<span class="lineNum">    1995 </span>            : }
<span class="lineNum">    1996 </span>            : 
<span class="lineNum">    1997 </span>            : template&lt;typename _Tp&gt; inline bool Point_&lt;_Tp&gt;::inside( const Rect_&lt;_Tp&gt;&amp; r ) const
<span class="lineNum">    1998 </span>            : {
<span class="lineNum">    1999 </span>            :     return r.contains(*this);
<span class="lineNum">    2000 </span>            : }
<span class="lineNum">    2001 </span>            : 
<span class="lineNum">    2002 </span>            : inline RotatedRect::RotatedRect() { angle = 0; }
<span class="lineNum">    2003 </span>            : inline RotatedRect::RotatedRect(const Point2f&amp; _center, const Size2f&amp; _size, float _angle)
<span class="lineNum">    2004 </span>            :     : center(_center), size(_size), angle(_angle) {}
<span class="lineNum">    2005 </span>            : inline RotatedRect::RotatedRect(const CvBox2D&amp; box)
<span class="lineNum">    2006 </span>            :     : center(box.center), size(box.size), angle(box.angle) {}
<span class="lineNum">    2007 </span>            : inline RotatedRect::operator CvBox2D() const
<span class="lineNum">    2008 </span>            : {
<span class="lineNum">    2009 </span>            :     CvBox2D box; box.center = center; box.size = size; box.angle = angle;
<span class="lineNum">    2010 </span>            :     return box;
<span class="lineNum">    2011 </span>            : }
<span class="lineNum">    2012 </span>            : 
<span class="lineNum">    2013 </span>            : //////////////////////////////// Scalar_ ///////////////////////////////
<span class="lineNum">    2014 </span>            : 
<span class="lineNum">    2015 </span>            : template&lt;typename _Tp&gt; inline Scalar_&lt;_Tp&gt;::Scalar_()
<span class="lineNum">    2016 </span>            : { this-&gt;val[0] = this-&gt;val[1] = this-&gt;val[2] = this-&gt;val[3] = 0; }
<span class="lineNum">    2017 </span>            : 
<span class="lineNum">    2018 </span>            : template&lt;typename _Tp&gt; inline Scalar_&lt;_Tp&gt;::Scalar_(_Tp v0, _Tp v1, _Tp v2, _Tp v3)
<span class="lineNum">    2019 </span>            : { this-&gt;val[0] = v0; this-&gt;val[1] = v1; this-&gt;val[2] = v2; this-&gt;val[3] = v3; }
<span class="lineNum">    2020 </span>            : 
<span class="lineNum">    2021 </span>            : template&lt;typename _Tp&gt; inline Scalar_&lt;_Tp&gt;::Scalar_(const CvScalar&amp; s)
<span class="lineNum">    2022 </span>            : {
<span class="lineNum">    2023 </span>            :     this-&gt;val[0] = saturate_cast&lt;_Tp&gt;(s.val[0]);
<span class="lineNum">    2024 </span>            :     this-&gt;val[1] = saturate_cast&lt;_Tp&gt;(s.val[1]);
<span class="lineNum">    2025 </span>            :     this-&gt;val[2] = saturate_cast&lt;_Tp&gt;(s.val[2]);
<span class="lineNum">    2026 </span>            :     this-&gt;val[3] = saturate_cast&lt;_Tp&gt;(s.val[3]);
<span class="lineNum">    2027 </span>            : }
<span class="lineNum">    2028 </span>            : 
<span class="lineNum">    2029 </span>            : template&lt;typename _Tp&gt; inline Scalar_&lt;_Tp&gt;::Scalar_(_Tp v0)
<span class="lineNum">    2030 </span>            : { this-&gt;val[0] = v0; this-&gt;val[1] = this-&gt;val[2] = this-&gt;val[3] = 0; }
<span class="lineNum">    2031 </span>            : 
<span class="lineNum">    2032 </span>            : template&lt;typename _Tp&gt; inline Scalar_&lt;_Tp&gt; Scalar_&lt;_Tp&gt;::all(_Tp v0)
<span class="lineNum">    2033 </span>            : { return Scalar_&lt;_Tp&gt;(v0, v0, v0, v0); }
<span class="lineNum">    2034 </span>            : template&lt;typename _Tp&gt; inline Scalar_&lt;_Tp&gt;::operator CvScalar() const
<span class="lineNum">    2035 </span>            : { return cvScalar(this-&gt;val[0], this-&gt;val[1], this-&gt;val[2], this-&gt;val[3]); }
<span class="lineNum">    2036 </span>            : 
<span class="lineNum">    2037 </span>            : template&lt;typename _Tp&gt; template&lt;typename T2&gt; inline Scalar_&lt;_Tp&gt;::operator Scalar_&lt;T2&gt;() const
<span class="lineNum">    2038 </span>            : {
<span class="lineNum">    2039 </span>            :     return Scalar_&lt;T2&gt;(saturate_cast&lt;T2&gt;(this-&gt;val[0]),
<span class="lineNum">    2040 </span>            :                   saturate_cast&lt;T2&gt;(this-&gt;val[1]),
<span class="lineNum">    2041 </span>            :                   saturate_cast&lt;T2&gt;(this-&gt;val[2]),
<span class="lineNum">    2042 </span>            :                   saturate_cast&lt;T2&gt;(this-&gt;val[3]));
<span class="lineNum">    2043 </span>            : }
<span class="lineNum">    2044 </span>            : 
<span class="lineNum">    2045 </span>            : template&lt;typename _Tp&gt; static inline Scalar_&lt;_Tp&gt;&amp; operator += (Scalar_&lt;_Tp&gt;&amp; a, const Scalar_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    2046 </span>            : {
<span class="lineNum">    2047 </span>            :     a.val[0] = saturate_cast&lt;_Tp&gt;(a.val[0] + b.val[0]);
<span class="lineNum">    2048 </span>            :     a.val[1] = saturate_cast&lt;_Tp&gt;(a.val[1] + b.val[1]);
<span class="lineNum">    2049 </span>            :     a.val[2] = saturate_cast&lt;_Tp&gt;(a.val[2] + b.val[2]);
<span class="lineNum">    2050 </span>            :     a.val[3] = saturate_cast&lt;_Tp&gt;(a.val[3] + b.val[3]);
<span class="lineNum">    2051 </span>            :     return a;
<span class="lineNum">    2052 </span>            : }
<span class="lineNum">    2053 </span>            : 
<span class="lineNum">    2054 </span>            : template&lt;typename _Tp&gt; static inline Scalar_&lt;_Tp&gt;&amp; operator -= (Scalar_&lt;_Tp&gt;&amp; a, const Scalar_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    2055 </span>            : {
<span class="lineNum">    2056 </span>            :     a.val[0] = saturate_cast&lt;_Tp&gt;(a.val[0] - b.val[0]);
<span class="lineNum">    2057 </span>            :     a.val[1] = saturate_cast&lt;_Tp&gt;(a.val[1] - b.val[1]);
<span class="lineNum">    2058 </span>            :     a.val[2] = saturate_cast&lt;_Tp&gt;(a.val[2] - b.val[2]);
<span class="lineNum">    2059 </span>            :     a.val[3] = saturate_cast&lt;_Tp&gt;(a.val[3] - b.val[3]);
<span class="lineNum">    2060 </span>            :     return a;
<span class="lineNum">    2061 </span>            : }
<span class="lineNum">    2062 </span>            : 
<span class="lineNum">    2063 </span>            : template&lt;typename _Tp&gt; static inline Scalar_&lt;_Tp&gt;&amp; operator *= ( Scalar_&lt;_Tp&gt;&amp; a, _Tp v )
<span class="lineNum">    2064 </span>            : {
<span class="lineNum">    2065 </span>            :     a.val[0] = saturate_cast&lt;_Tp&gt;(a.val[0] * v);
<span class="lineNum">    2066 </span>            :     a.val[1] = saturate_cast&lt;_Tp&gt;(a.val[1] * v);
<span class="lineNum">    2067 </span>            :     a.val[2] = saturate_cast&lt;_Tp&gt;(a.val[2] * v);
<span class="lineNum">    2068 </span>            :     a.val[3] = saturate_cast&lt;_Tp&gt;(a.val[3] * v);
<span class="lineNum">    2069 </span>            :     return a;
<span class="lineNum">    2070 </span>            : }
<span class="lineNum">    2071 </span>            : 
<span class="lineNum">    2072 </span>            : template&lt;typename _Tp&gt; inline Scalar_&lt;_Tp&gt; Scalar_&lt;_Tp&gt;::mul(const Scalar_&lt;_Tp&gt;&amp; t, double scale ) const
<span class="lineNum">    2073 </span>            : {
<span class="lineNum">    2074 </span>            :     return Scalar_&lt;_Tp&gt;( saturate_cast&lt;_Tp&gt;(this-&gt;val[0]*t.val[0]*scale),
<span class="lineNum">    2075 </span>            :                        saturate_cast&lt;_Tp&gt;(this-&gt;val[1]*t.val[1]*scale),
<span class="lineNum">    2076 </span>            :                        saturate_cast&lt;_Tp&gt;(this-&gt;val[2]*t.val[2]*scale),
<span class="lineNum">    2077 </span>            :                        saturate_cast&lt;_Tp&gt;(this-&gt;val[3]*t.val[3]*scale));
<span class="lineNum">    2078 </span>            : }
<span class="lineNum">    2079 </span>            : 
<span class="lineNum">    2080 </span>            : template&lt;typename _Tp&gt; static inline bool operator == ( const Scalar_&lt;_Tp&gt;&amp; a, const Scalar_&lt;_Tp&gt;&amp; b )
<span class="lineNum">    2081 </span>            : {
<span class="lineNum">    2082 </span>            :     return a.val[0] == b.val[0] &amp;&amp; a.val[1] == b.val[1] &amp;&amp;
<span class="lineNum">    2083 </span>            :         a.val[2] == b.val[2] &amp;&amp; a.val[3] == b.val[3];
<span class="lineNum">    2084 </span>            : }
<span class="lineNum">    2085 </span>            : 
<span class="lineNum">    2086 </span>            : template&lt;typename _Tp&gt; static inline bool operator != ( const Scalar_&lt;_Tp&gt;&amp; a, const Scalar_&lt;_Tp&gt;&amp; b )
<span class="lineNum">    2087 </span>            : {
<span class="lineNum">    2088 </span>            :     return a.val[0] != b.val[0] || a.val[1] != b.val[1] ||
<span class="lineNum">    2089 </span>            :         a.val[2] != b.val[2] || a.val[3] != b.val[3];
<span class="lineNum">    2090 </span>            : }
<span class="lineNum">    2091 </span>            : 
<span class="lineNum">    2092 </span>            : template&lt;typename _Tp&gt; static inline Scalar_&lt;_Tp&gt; operator + (const Scalar_&lt;_Tp&gt;&amp; a, const Scalar_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    2093 </span>            : {
<span class="lineNum">    2094 </span>            :     return Scalar_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(a.val[0] + b.val[0]),
<span class="lineNum">    2095 </span>            :                       saturate_cast&lt;_Tp&gt;(a.val[1] + b.val[1]),
<span class="lineNum">    2096 </span>            :                       saturate_cast&lt;_Tp&gt;(a.val[2] + b.val[2]),
<span class="lineNum">    2097 </span>            :                       saturate_cast&lt;_Tp&gt;(a.val[3] + b.val[3]));
<span class="lineNum">    2098 </span>            : }
<span class="lineNum">    2099 </span>            : 
<span class="lineNum">    2100 </span>            : template&lt;typename _Tp&gt; static inline Scalar_&lt;_Tp&gt; operator - (const Scalar_&lt;_Tp&gt;&amp; a, const Scalar_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    2101 </span>            : {
<span class="lineNum">    2102 </span>            :     return Scalar_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(a.val[0] - b.val[0]),
<span class="lineNum">    2103 </span>            :                       saturate_cast&lt;_Tp&gt;(a.val[1] - b.val[1]),
<span class="lineNum">    2104 </span>            :                       saturate_cast&lt;_Tp&gt;(a.val[2] - b.val[2]),
<span class="lineNum">    2105 </span>            :                       saturate_cast&lt;_Tp&gt;(a.val[3] - b.val[3]));
<span class="lineNum">    2106 </span>            : }
<span class="lineNum">    2107 </span>            : 
<span class="lineNum">    2108 </span>            : template&lt;typename _Tp&gt; static inline Scalar_&lt;_Tp&gt; operator * (const Scalar_&lt;_Tp&gt;&amp; a, _Tp alpha)
<span class="lineNum">    2109 </span>            : {
<span class="lineNum">    2110 </span>            :     return Scalar_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(a.val[0] * alpha),
<span class="lineNum">    2111 </span>            :                       saturate_cast&lt;_Tp&gt;(a.val[1] * alpha),
<span class="lineNum">    2112 </span>            :                       saturate_cast&lt;_Tp&gt;(a.val[2] * alpha),
<span class="lineNum">    2113 </span>            :                       saturate_cast&lt;_Tp&gt;(a.val[3] * alpha));
<span class="lineNum">    2114 </span>            : }
<span class="lineNum">    2115 </span>            : 
<span class="lineNum">    2116 </span>            : template&lt;typename _Tp&gt; static inline Scalar_&lt;_Tp&gt; operator * (_Tp alpha, const Scalar_&lt;_Tp&gt;&amp; a)
<span class="lineNum">    2117 </span>            : {
<span class="lineNum">    2118 </span>            :     return a*alpha;
<span class="lineNum">    2119 </span>            : }
<span class="lineNum">    2120 </span>            : 
<span class="lineNum">    2121 </span>            : template&lt;typename _Tp&gt; static inline Scalar_&lt;_Tp&gt; operator - (const Scalar_&lt;_Tp&gt;&amp; a)
<span class="lineNum">    2122 </span>            : {
<span class="lineNum">    2123 </span>            :     return Scalar_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(-a.val[0]), saturate_cast&lt;_Tp&gt;(-a.val[1]),
<span class="lineNum">    2124 </span>            :                       saturate_cast&lt;_Tp&gt;(-a.val[2]), saturate_cast&lt;_Tp&gt;(-a.val[3]));
<span class="lineNum">    2125 </span>            : }
<span class="lineNum">    2126 </span>            : 
<span class="lineNum">    2127 </span>            : 
<span class="lineNum">    2128 </span>            : template&lt;typename _Tp&gt; static inline Scalar_&lt;_Tp&gt;
<span class="lineNum">    2129 </span>            : operator * (const Scalar_&lt;_Tp&gt;&amp; a, const Scalar_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    2130 </span>            : {
<span class="lineNum">    2131 </span>            :     return Scalar_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(a[0]*b[0] - a[1]*b[1] - a[2]*b[2] - a[3]*b[3]),
<span class="lineNum">    2132 </span>            :                         saturate_cast&lt;_Tp&gt;(a[0]*b[1] + a[1]*b[0] + a[2]*b[3] - a[3]*b[2]),
<span class="lineNum">    2133 </span>            :                         saturate_cast&lt;_Tp&gt;(a[0]*b[2] - a[1]*b[3] + a[2]*b[0] + a[3]*b[1]),
<span class="lineNum">    2134 </span>            :                         saturate_cast&lt;_Tp&gt;(a[0]*b[3] + a[1]*b[2] - a[2]*b[1] + a[3]*b[0]));
<span class="lineNum">    2135 </span>            : }
<span class="lineNum">    2136 </span>            : 
<span class="lineNum">    2137 </span>            : template&lt;typename _Tp&gt; static inline Scalar_&lt;_Tp&gt;&amp;
<span class="lineNum">    2138 </span>            : operator *= (Scalar_&lt;_Tp&gt;&amp; a, const Scalar_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    2139 </span>            : {
<span class="lineNum">    2140 </span>            :     a = a*b;
<span class="lineNum">    2141 </span>            :     return a;
<span class="lineNum">    2142 </span>            : }
<span class="lineNum">    2143 </span>            : 
<span class="lineNum">    2144 </span>            : template&lt;typename _Tp&gt; inline Scalar_&lt;_Tp&gt; Scalar_&lt;_Tp&gt;::conj() const
<span class="lineNum">    2145 </span>            : {
<span class="lineNum">    2146 </span>            :     return Scalar_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(this-&gt;val[0]),
<span class="lineNum">    2147 </span>            :                         saturate_cast&lt;_Tp&gt;(-this-&gt;val[1]),
<span class="lineNum">    2148 </span>            :                         saturate_cast&lt;_Tp&gt;(-this-&gt;val[2]),
<span class="lineNum">    2149 </span>            :                         saturate_cast&lt;_Tp&gt;(-this-&gt;val[3]));
<span class="lineNum">    2150 </span>            : }
<span class="lineNum">    2151 </span>            : 
<span class="lineNum">    2152 </span>            : template&lt;typename _Tp&gt; inline bool Scalar_&lt;_Tp&gt;::isReal() const
<span class="lineNum">    2153 </span>            : {
<span class="lineNum">    2154 </span>            :     return this-&gt;val[1] == 0 &amp;&amp; this-&gt;val[2] == 0 &amp;&amp; this-&gt;val[3] == 0;
<span class="lineNum">    2155 </span>            : }
<span class="lineNum">    2156 </span>            : 
<span class="lineNum">    2157 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    2158 </span>            : Scalar_&lt;_Tp&gt; operator / (const Scalar_&lt;_Tp&gt;&amp; a, _Tp alpha)
<span class="lineNum">    2159 </span>            : {
<span class="lineNum">    2160 </span>            :     return Scalar_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(a.val[0] / alpha),
<span class="lineNum">    2161 </span>            :                         saturate_cast&lt;_Tp&gt;(a.val[1] / alpha),
<span class="lineNum">    2162 </span>            :                         saturate_cast&lt;_Tp&gt;(a.val[2] / alpha),
<span class="lineNum">    2163 </span>            :                         saturate_cast&lt;_Tp&gt;(a.val[3] / alpha));
<span class="lineNum">    2164 </span>            : }
<span class="lineNum">    2165 </span>            : 
<span class="lineNum">    2166 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    2167 </span>            : Scalar_&lt;float&gt; operator / (const Scalar_&lt;float&gt;&amp; a, float alpha)
<span class="lineNum">    2168 </span>            : {
<span class="lineNum">    2169 </span>            :     float s = 1/alpha;
<span class="lineNum">    2170 </span>            :     return Scalar_&lt;float&gt;(a.val[0]*s, a.val[1]*s, a.val[2]*s, a.val[3]*s);
<span class="lineNum">    2171 </span>            : }
<span class="lineNum">    2172 </span>            : 
<span class="lineNum">    2173 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    2174 </span>            : Scalar_&lt;double&gt; operator / (const Scalar_&lt;double&gt;&amp; a, double alpha)
<span class="lineNum">    2175 </span>            : {
<span class="lineNum">    2176 </span>            :     double s = 1/alpha;
<span class="lineNum">    2177 </span>            :     return Scalar_&lt;double&gt;(a.val[0]*s, a.val[1]*s, a.val[2]*s, a.val[3]*s);
<span class="lineNum">    2178 </span>            : }
<span class="lineNum">    2179 </span>            : 
<span class="lineNum">    2180 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    2181 </span>            : Scalar_&lt;_Tp&gt;&amp; operator /= (Scalar_&lt;_Tp&gt;&amp; a, _Tp alpha)
<span class="lineNum">    2182 </span>            : {
<span class="lineNum">    2183 </span>            :     a = a/alpha;
<span class="lineNum">    2184 </span>            :     return a;
<span class="lineNum">    2185 </span>            : }
<span class="lineNum">    2186 </span>            : 
<span class="lineNum">    2187 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    2188 </span>            : Scalar_&lt;_Tp&gt; operator / (_Tp a, const Scalar_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    2189 </span>            : {
<span class="lineNum">    2190 </span>            :     _Tp s = a/(b[0]*b[0] + b[1]*b[1] + b[2]*b[2] + b[3]*b[3]);
<span class="lineNum">    2191 </span>            :     return b.conj()*s;
<span class="lineNum">    2192 </span>            : }
<span class="lineNum">    2193 </span>            : 
<span class="lineNum">    2194 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    2195 </span>            : Scalar_&lt;_Tp&gt; operator / (const Scalar_&lt;_Tp&gt;&amp; a, const Scalar_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    2196 </span>            : {
<span class="lineNum">    2197 </span>            :     return a*((_Tp)1/b);
<span class="lineNum">    2198 </span>            : }
<span class="lineNum">    2199 </span>            : 
<span class="lineNum">    2200 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    2201 </span>            : Scalar_&lt;_Tp&gt;&amp; operator /= (Scalar_&lt;_Tp&gt;&amp; a, const Scalar_&lt;_Tp&gt;&amp; b)
<span class="lineNum">    2202 </span>            : {
<span class="lineNum">    2203 </span>            :     a = a/b;
<span class="lineNum">    2204 </span>            :     return a;
<span class="lineNum">    2205 </span>            : }
<span class="lineNum">    2206 </span>            : 
<span class="lineNum">    2207 </span>            : //////////////////////////////// Range /////////////////////////////////
<span class="lineNum">    2208 </span>            : 
<span class="lineNum">    2209 </span>            : inline Range::Range() : start(0), end(0) {}
<span class="lineNum">    2210 </span>            : inline Range::Range(int _start, int _end) : start(_start), end(_end) {}
<span class="lineNum">    2211 </span>            : inline Range::Range(const CvSlice&amp; slice) : start(slice.start_index), end(slice.end_index)
<span class="lineNum">    2212 </span>            : {
<span class="lineNum">    2213 </span>            :     if( start == 0 &amp;&amp; end == CV_WHOLE_SEQ_END_INDEX )
<span class="lineNum">    2214 </span>            :         *this = Range::all();
<span class="lineNum">    2215 </span>            : }
<span class="lineNum">    2216 </span>            : 
<span class="lineNum">    2217 </span>            : inline int Range::size() const { return end - start; }
<span class="lineNum">    2218 </span>            : inline bool Range::empty() const { return start == end; }
<span class="lineNum">    2219 </span>            : inline Range Range::all() { return Range(INT_MIN, INT_MAX); }
<span class="lineNum">    2220 </span>            : 
<span class="lineNum">    2221 </span>            : static inline bool operator == (const Range&amp; r1, const Range&amp; r2)
<span class="lineNum">    2222 </span>            : { return r1.start == r2.start &amp;&amp; r1.end == r2.end; }
<span class="lineNum">    2223 </span>            : 
<span class="lineNum">    2224 </span>            : static inline bool operator != (const Range&amp; r1, const Range&amp; r2)
<span class="lineNum">    2225 </span>            : { return !(r1 == r2); }
<span class="lineNum">    2226 </span>            : 
<span class="lineNum">    2227 </span>            : static inline bool operator !(const Range&amp; r)
<span class="lineNum">    2228 </span>            : { return r.start == r.end; }
<span class="lineNum">    2229 </span>            : 
<span class="lineNum">    2230 </span>            : static inline Range operator &amp; (const Range&amp; r1, const Range&amp; r2)
<span class="lineNum">    2231 </span>            : {
<span class="lineNum">    2232 </span>            :     Range r(std::max(r1.start, r2.start), std::min(r1.end, r2.end));
<span class="lineNum">    2233 </span>            :     r.end = std::max(r.end, r.start);
<span class="lineNum">    2234 </span>            :     return r;
<span class="lineNum">    2235 </span>            : }
<span class="lineNum">    2236 </span>            : 
<span class="lineNum">    2237 </span>            : static inline Range&amp; operator &amp;= (Range&amp; r1, const Range&amp; r2)
<span class="lineNum">    2238 </span>            : {
<span class="lineNum">    2239 </span>            :     r1 = r1 &amp; r2;
<span class="lineNum">    2240 </span>            :     return r1;
<span class="lineNum">    2241 </span>            : }
<span class="lineNum">    2242 </span>            : 
<span class="lineNum">    2243 </span>            : static inline Range operator + (const Range&amp; r1, int delta)
<span class="lineNum">    2244 </span>            : {
<span class="lineNum">    2245 </span>            :     return Range(r1.start + delta, r1.end + delta);
<span class="lineNum">    2246 </span>            : }
<span class="lineNum">    2247 </span>            : 
<span class="lineNum">    2248 </span>            : static inline Range operator + (int delta, const Range&amp; r1)
<span class="lineNum">    2249 </span>            : {
<span class="lineNum">    2250 </span>            :     return Range(r1.start + delta, r1.end + delta);
<span class="lineNum">    2251 </span>            : }
<span class="lineNum">    2252 </span>            : 
<span class="lineNum">    2253 </span>            : static inline Range operator - (const Range&amp; r1, int delta)
<span class="lineNum">    2254 </span>            : {
<span class="lineNum">    2255 </span>            :     return r1 + (-delta);
<span class="lineNum">    2256 </span>            : }
<span class="lineNum">    2257 </span>            : 
<span class="lineNum">    2258 </span>            : inline Range::operator CvSlice() const
<span class="lineNum">    2259 </span>            : { return *this != Range::all() ? cvSlice(start, end) : CV_WHOLE_SEQ; }
<span class="lineNum">    2260 </span>            : 
<span class="lineNum">    2261 </span>            : 
<span class="lineNum">    2262 </span>            : 
<span class="lineNum">    2263 </span>            : //////////////////////////////// Vector ////////////////////////////////
<span class="lineNum">    2264 </span>            : 
<span class="lineNum">    2265 </span>            : // template vector class. It is similar to STL's vector,
<span class="lineNum">    2266 </span>            : // with a few important differences:
<span class="lineNum">    2267 </span>            : //   1) it can be created on top of user-allocated data w/o copying it
<span class="lineNum">    2268 </span>            : //   2) vector b = a means copying the header,
<span class="lineNum">    2269 </span>            : //      not the underlying data (use clone() to make a deep copy)
<span class="lineNum">    2270 </span>            : template &lt;typename _Tp&gt; class Vector
<span class="lineNum">    2271 </span>            : {
<span class="lineNum">    2272 </span>            : public:
<span class="lineNum">    2273 </span>            :     typedef _Tp value_type;
<span class="lineNum">    2274 </span>            :     typedef _Tp* iterator;
<span class="lineNum">    2275 </span>            :     typedef const _Tp* const_iterator;
<span class="lineNum">    2276 </span>            :     typedef _Tp&amp; reference;
<span class="lineNum">    2277 </span>            :     typedef const _Tp&amp; const_reference;
<span class="lineNum">    2278 </span>            : 
<span class="lineNum">    2279 </span>            :     struct Hdr
<span class="lineNum">    2280 </span>            :     {
<span class="lineNum">    2281 </span>            :         Hdr() : data(0), datastart(0), refcount(0), size(0), capacity(0) {};
<span class="lineNum">    2282 </span>            :         _Tp* data;
<span class="lineNum">    2283 </span>            :         _Tp* datastart;
<span class="lineNum">    2284 </span>            :         _Atomic_word* refcount;
<span class="lineNum">    2285 </span>            :         size_t size;
<span class="lineNum">    2286 </span>            :         size_t capacity;
<span class="lineNum">    2287 </span>            :     };
<span class="lineNum">    2288 </span>            : 
<span class="lineNum">    2289 </span>            :     Vector() {}
<span class="lineNum">    2290 </span>            :     Vector(size_t _size)  { resize(_size); }
<span class="lineNum">    2291 </span>            :     Vector(size_t _size, const _Tp&amp; val)
<span class="lineNum">    2292 </span>            :     {
<span class="lineNum">    2293 </span>            :         resize(_size);
<span class="lineNum">    2294 </span>            :         for(size_t i = 0; i &lt; _size; i++)
<span class="lineNum">    2295 </span>            :             hdr.data[i] = val;
<span class="lineNum">    2296 </span>            :     }
<span class="lineNum">    2297 </span>            :     Vector(_Tp* _data, size_t _size, bool _copyData=false)
<span class="lineNum">    2298 </span>            :     { set(_data, _size, _copyData); }
<span class="lineNum">    2299 </span>            : 
<span class="lineNum">    2300 </span>            :     template&lt;int n&gt; Vector(const Vec&lt;_Tp, n&gt;&amp; vec)
<span class="lineNum">    2301 </span>            :     { set((_Tp*)&amp;vec.val[0], n, true); }
<span class="lineNum">    2302 </span>            : 
<span class="lineNum">    2303 </span>            :     Vector(const std::vector&lt;_Tp&gt;&amp; vec, bool _copyData=false)
<span class="lineNum">    2304 </span>            :     { set(!vec.empty() ? (_Tp*)&amp;vec[0] : 0, vec.size(), _copyData); }
<span class="lineNum">    2305 </span>            : 
<span class="lineNum">    2306 </span>            :     Vector(const Vector&amp; d) { *this = d; }
<span class="lineNum">    2307 </span>            : 
<span class="lineNum">    2308 </span>            :     Vector(const Vector&amp; d, const Range&amp; r_)
<span class="lineNum">    2309 </span>            :     {
<span class="lineNum">    2310 </span>            :         Range r = r_ == Range::all() ? Range(0, d.size()) : r_;
<span class="lineNum">    2311 </span>            :         /*if( r == Range::all() )
<span class="lineNum">    2312 </span>            :             r = Range(0, d.size());*/
<span class="lineNum">    2313 </span>            :         if( r.size() &gt; 0 &amp;&amp; r.start &gt;= 0 &amp;&amp; r.end &lt;= d.size() )
<span class="lineNum">    2314 </span>            :         {
<span class="lineNum">    2315 </span>            :             if( d.hdr.refcount )
<span class="lineNum">    2316 </span>            :                 CV_XADD(d.hdr.refcount, 1);
<span class="lineNum">    2317 </span>            :             hdr.refcount = d.hdr.refcount;
<span class="lineNum">    2318 </span>            :             hdr.datastart = d.hdr.datastart;
<span class="lineNum">    2319 </span>            :             hdr.data = d.hdr.data + r.start;
<span class="lineNum">    2320 </span>            :             hdr.capacity = hdr.size = r.size();
<span class="lineNum">    2321 </span>            :         }
<span class="lineNum">    2322 </span>            :     }
<span class="lineNum">    2323 </span>            : 
<span class="lineNum">    2324 </span>            :     Vector&lt;_Tp&gt;&amp; operator = (const Vector&amp; d)
<span class="lineNum">    2325 </span>            :     {
<span class="lineNum">    2326 </span>            :         if( this != &amp;d )
<span class="lineNum">    2327 </span>            :         {
<span class="lineNum">    2328 </span>            :             if( d.hdr.refcount )
<span class="lineNum">    2329 </span>            :                 CV_XADD(d.hdr.refcount, 1);
<span class="lineNum">    2330 </span>            :             release();
<span class="lineNum">    2331 </span>            :             hdr = d.hdr;
<span class="lineNum">    2332 </span>            :         }
<span class="lineNum">    2333 </span>            :         return *this;
<span class="lineNum">    2334 </span>            :     }
<span class="lineNum">    2335 </span>            : 
<span class="lineNum">    2336 </span>            :     ~Vector()  { release(); }
<span class="lineNum">    2337 </span>            : 
<span class="lineNum">    2338 </span>            :     Vector&lt;_Tp&gt; clone() const
<span class="lineNum">    2339 </span>            :     { return hdr.data ? Vector&lt;_Tp&gt;(hdr.data, hdr.size, true) : Vector&lt;_Tp&gt;(); }
<span class="lineNum">    2340 </span>            : 
<span class="lineNum">    2341 </span>            :     void copyTo(Vector&lt;_Tp&gt;&amp; vec) const
<span class="lineNum">    2342 </span>            :     {
<span class="lineNum">    2343 </span>            :         size_t i, sz = size();
<span class="lineNum">    2344 </span>            :         vec.resize(sz);
<span class="lineNum">    2345 </span>            :         const _Tp* src = hdr.data;
<span class="lineNum">    2346 </span>            :         _Tp* dst = vec.hdr.data;
<span class="lineNum">    2347 </span>            :         for( i = 0; i &lt; sz; i++ )
<span class="lineNum">    2348 </span>            :             dst[i] = src[i];
<span class="lineNum">    2349 </span>            :     }
<span class="lineNum">    2350 </span>            : 
<span class="lineNum">    2351 </span>            :     void copyTo(std::vector&lt;_Tp&gt;&amp; vec) const
<span class="lineNum">    2352 </span>            :     {
<span class="lineNum">    2353 </span>            :         size_t i, sz = size();
<span class="lineNum">    2354 </span>            :         vec.resize(sz);
<span class="lineNum">    2355 </span>            :         const _Tp* src = hdr.data;
<span class="lineNum">    2356 </span>            :         _Tp* dst = sz ? &amp;vec[0] : 0;
<span class="lineNum">    2357 </span>            :         for( i = 0; i &lt; sz; i++ )
<span class="lineNum">    2358 </span>            :             dst[i] = src[i];
<span class="lineNum">    2359 </span>            :     }
<span class="lineNum">    2360 </span>            : 
<span class="lineNum">    2361 </span>            :     operator CvMat() const
<span class="lineNum">    2362 </span>            :     { return cvMat((int)size(), 1, type(), (void*)hdr.data); }
<span class="lineNum">    2363 </span>            : 
<span class="lineNum">    2364 </span>            :     _Tp&amp; operator [] (size_t i) { CV_DbgAssert( i &lt; size() ); return hdr.data[i]; }
<span class="lineNum">    2365 </span>            :     const _Tp&amp; operator [] (size_t i) const { CV_DbgAssert( i &lt; size() ); return hdr.data[i]; }
<span class="lineNum">    2366 </span>            :     Vector operator() (const Range&amp; r) const { return Vector(*this, r); }
<span class="lineNum">    2367 </span>            :     _Tp&amp; back() { CV_DbgAssert(!empty()); return hdr.data[hdr.size-1]; }
<span class="lineNum">    2368 </span>            :     const _Tp&amp; back() const { CV_DbgAssert(!empty()); return hdr.data[hdr.size-1]; }
<span class="lineNum">    2369 </span>            :     _Tp&amp; front() { CV_DbgAssert(!empty()); return hdr.data[0]; }
<span class="lineNum">    2370 </span>            :     const _Tp&amp; front() const { CV_DbgAssert(!empty()); return hdr.data[0]; }
<span class="lineNum">    2371 </span>            : 
<span class="lineNum">    2372 </span>            :     _Tp* begin() { return hdr.data; }
<span class="lineNum">    2373 </span>            :     _Tp* end() { return hdr.data + hdr.size; }
<span class="lineNum">    2374 </span>            :     const _Tp* begin() const { return hdr.data; }
<span class="lineNum">    2375 </span>            :     const _Tp* end() const { return hdr.data + hdr.size; }
<span class="lineNum">    2376 </span>            : 
<span class="lineNum">    2377 </span>            :     void addref() { if( hdr.refcount ) CV_XADD(hdr.refcount, 1); }
<span class="lineNum">    2378 </span>            :     void release()
<span class="lineNum">    2379 </span>            :     {
<span class="lineNum">    2380 </span>            :         if( hdr.refcount &amp;&amp; CV_XADD(hdr.refcount, -1) == 1 )
<span class="lineNum">    2381 </span>            :         {
<span class="lineNum">    2382 </span>            :             delete[] hdr.datastart;
<span class="lineNum">    2383 </span>            :             delete hdr.refcount;
<span class="lineNum">    2384 </span>            :         }
<span class="lineNum">    2385 </span>            :         hdr = Hdr();
<span class="lineNum">    2386 </span>            :     }
<span class="lineNum">    2387 </span>            : 
<span class="lineNum">    2388 </span>            :     void set(_Tp* _data, size_t _size, bool _copyData=false)
<span class="lineNum">    2389 </span>            :     {
<span class="lineNum">    2390 </span>            :         if( !_copyData )
<span class="lineNum">    2391 </span>            :         {
<span class="lineNum">    2392 </span>            :             release();
<span class="lineNum">    2393 </span>            :             hdr.data = hdr.datastart = _data;
<span class="lineNum">    2394 </span>            :             hdr.size = hdr.capacity = _size;
<span class="lineNum">    2395 </span>            :             hdr.refcount = 0;
<span class="lineNum">    2396 </span>            :         }
<span class="lineNum">    2397 </span>            :         else
<span class="lineNum">    2398 </span>            :         {
<span class="lineNum">    2399 </span>            :             reserve(_size);
<span class="lineNum">    2400 </span>            :             for( size_t i = 0; i &lt; _size; i++ )
<span class="lineNum">    2401 </span>            :                 hdr.data[i] = _data[i];
<span class="lineNum">    2402 </span>            :             hdr.size = _size;
<span class="lineNum">    2403 </span>            :         }
<span class="lineNum">    2404 </span>            :     }
<span class="lineNum">    2405 </span>            : 
<span class="lineNum">    2406 </span>            :     void reserve(size_t newCapacity)
<span class="lineNum">    2407 </span>            :     {
<span class="lineNum">    2408 </span>            :         _Tp* newData;
<span class="lineNum">    2409 </span>            :         int* newRefcount;
<span class="lineNum">    2410 </span>            :         size_t i, oldSize = hdr.size;
<span class="lineNum">    2411 </span>            :         if( (!hdr.refcount || *hdr.refcount == 1) &amp;&amp; hdr.capacity &gt;= newCapacity )
<span class="lineNum">    2412 </span>            :             return;
<span class="lineNum">    2413 </span>            :         newCapacity = std::max(newCapacity, oldSize);
<span class="lineNum">    2414 </span>            :         newData = new _Tp[newCapacity];
<span class="lineNum">    2415 </span>            :         newRefcount = new int(1);
<span class="lineNum">    2416 </span>            :         for( i = 0; i &lt; oldSize; i++ )
<span class="lineNum">    2417 </span>            :             newData[i] = hdr.data[i];
<span class="lineNum">    2418 </span>            :         release();
<span class="lineNum">    2419 </span>            :         hdr.data = hdr.datastart = newData;
<span class="lineNum">    2420 </span>            :         hdr.capacity = newCapacity;
<span class="lineNum">    2421 </span>            :         hdr.size = oldSize;
<span class="lineNum">    2422 </span>            :         hdr.refcount = newRefcount;
<span class="lineNum">    2423 </span>            :     }
<span class="lineNum">    2424 </span>            : 
<span class="lineNum">    2425 </span>            :     void resize(size_t newSize)
<span class="lineNum">    2426 </span>            :     {
<span class="lineNum">    2427 </span>            :         size_t i;
<span class="lineNum">    2428 </span>            :         newSize = std::max(newSize, (size_t)0);
<span class="lineNum">    2429 </span>            :         if( (!hdr.refcount || *hdr.refcount == 1) &amp;&amp; hdr.size == newSize )
<span class="lineNum">    2430 </span>            :             return;
<span class="lineNum">    2431 </span>            :         if( newSize &gt; hdr.capacity )
<span class="lineNum">    2432 </span>            :             reserve(std::max(newSize, std::max((size_t)4, hdr.capacity*2)));
<span class="lineNum">    2433 </span>            :         for( i = hdr.size; i &lt; newSize; i++ )
<span class="lineNum">    2434 </span>            :             hdr.data[i] = _Tp();
<span class="lineNum">    2435 </span>            :         hdr.size = newSize;
<span class="lineNum">    2436 </span>            :     }
<span class="lineNum">    2437 </span>            : 
<span class="lineNum">    2438 </span>            :     Vector&lt;_Tp&gt;&amp; push_back(const _Tp&amp; elem)
<span class="lineNum">    2439 </span>            :     {
<span class="lineNum">    2440 </span>            :         if( hdr.size == hdr.capacity )
<span class="lineNum">    2441 </span>            :             reserve( std::max((size_t)4, hdr.capacity*2) );
<span class="lineNum">    2442 </span>            :         hdr.data[hdr.size++] = elem;
<span class="lineNum">    2443 </span>            :         return *this;
<span class="lineNum">    2444 </span>            :     }
<span class="lineNum">    2445 </span>            : 
<span class="lineNum">    2446 </span>            :     Vector&lt;_Tp&gt;&amp; pop_back()
<span class="lineNum">    2447 </span>            :     {
<span class="lineNum">    2448 </span>            :         if( hdr.size &gt; 0 )
<span class="lineNum">    2449 </span>            :             --hdr.size;
<span class="lineNum">    2450 </span>            :         return *this;
<span class="lineNum">    2451 </span>            :     }
<span class="lineNum">    2452 </span>            : 
<span class="lineNum">    2453 </span>            :     size_t size() const { return hdr.size; }
<span class="lineNum">    2454 </span>            :     size_t capacity() const { return hdr.capacity; }
<span class="lineNum">    2455 </span>            :     bool empty() const { return hdr.size == 0; }
<span class="lineNum">    2456 </span>            :     void clear() { resize(0); }
<span class="lineNum">    2457 </span>            :     int type() const { return DataType&lt;_Tp&gt;::type; }
<span class="lineNum">    2458 </span>            : 
<span class="lineNum">    2459 </span>            : protected:
<span class="lineNum">    2460 </span>            :     Hdr hdr;
<span class="lineNum">    2461 </span>            : };
<span class="lineNum">    2462 </span>            : 
<span class="lineNum">    2463 </span>            : 
<span class="lineNum">    2464 </span>            : template&lt;typename _Tp&gt; inline typename DataType&lt;_Tp&gt;::work_type
<span class="lineNum">    2465 </span>            : dot(const Vector&lt;_Tp&gt;&amp; v1, const Vector&lt;_Tp&gt;&amp; v2)
<span class="lineNum">    2466 </span>            : {
<span class="lineNum">    2467 </span>            :     typedef typename DataType&lt;_Tp&gt;::work_type _Tw;
<span class="lineNum">    2468 </span>            :     size_t i = 0, n = v1.size();
<span class="lineNum">    2469 </span>            :     assert(v1.size() == v2.size());
<span class="lineNum">    2470 </span>            : 
<span class="lineNum">    2471 </span>            :     _Tw s = 0;
<span class="lineNum">    2472 </span>            :     const _Tp *ptr1 = &amp;v1[0], *ptr2 = &amp;v2[0];
<span class="lineNum">    2473 </span>            :     for( ; i &lt; n; i++ )
<span class="lineNum">    2474 </span>            :         s += (_Tw)ptr1[i]*ptr2[i];
<span class="lineNum">    2475 </span>            : 
<span class="lineNum">    2476 </span>            :     return s;
<span class="lineNum">    2477 </span>            : }
<span class="lineNum">    2478 </span>            : 
<span class="lineNum">    2479 </span>            : // Multiply-with-Carry RNG
<span class="lineNum">    2480 </span>            : inline RNG::RNG() { state = 0xffffffff; }
<span class="lineNum">    2481 </span>            : inline RNG::RNG(uint64 _state) { state = _state ? _state : 0xffffffff; }
<span class="lineNum">    2482 </span>            : inline unsigned RNG::next()
<span class="lineNum">    2483 </span>            : {
<span class="lineNum">    2484 </span>            :     state = (uint64)(unsigned)state*CV_RNG_COEFF + (unsigned)(state &gt;&gt; 32);
<span class="lineNum">    2485 </span>            :     return (unsigned)state;
<span class="lineNum">    2486 </span>            : }
<span class="lineNum">    2487 </span>            : 
<span class="lineNum">    2488 </span>            : inline RNG::operator uchar() { return (uchar)next(); }
<span class="lineNum">    2489 </span>            : inline RNG::operator schar() { return (schar)next(); }
<span class="lineNum">    2490 </span>            : inline RNG::operator ushort() { return (ushort)next(); }
<span class="lineNum">    2491 </span>            : inline RNG::operator short() { return (short)next(); }
<span class="lineNum">    2492 </span>            : inline RNG::operator unsigned() { return next(); }
<span class="lineNum">    2493 </span>            : inline unsigned RNG::operator ()(unsigned N) {return (unsigned)uniform(0,N);}
<span class="lineNum">    2494 </span>            : inline unsigned RNG::operator ()() {return next();}
<span class="lineNum">    2495 </span>            : inline RNG::operator int() { return (int)next(); }
<span class="lineNum">    2496 </span>            : // * (2^32-1)^-1
<span class="lineNum">    2497 </span>            : inline RNG::operator float() { return next()*2.3283064365386962890625e-10f; }
<span class="lineNum">    2498 </span>            : inline RNG::operator double()
<span class="lineNum">    2499 </span>            : {
<span class="lineNum">    2500 </span>            :     unsigned t = next();
<span class="lineNum">    2501 </span>            :     return (((uint64)t &lt;&lt; 32) | next())*5.4210108624275221700372640043497e-20;
<span class="lineNum">    2502 </span>            : }
<span class="lineNum">    2503 </span>            : inline int RNG::uniform(int a, int b) { return a == b ? a : (int)(next()%(b - a) + a); }
<span class="lineNum">    2504 </span>            : inline float RNG::uniform(float a, float b) { return ((float)*this)*(b - a) + a; }
<span class="lineNum">    2505 </span>            : inline double RNG::uniform(double a, double b) { return ((double)*this)*(b - a) + a; }
<span class="lineNum">    2506 </span>            : 
<span class="lineNum">    2507 </span>            : inline TermCriteria::TermCriteria() : type(0), maxCount(0), epsilon(0) {}
<span class="lineNum">    2508 </span>            : inline TermCriteria::TermCriteria(int _type, int _maxCount, double _epsilon)
<span class="lineNum">    2509 </span>            :     : type(_type), maxCount(_maxCount), epsilon(_epsilon) {}
<span class="lineNum">    2510 </span>            : inline TermCriteria::TermCriteria(const CvTermCriteria&amp; criteria)
<span class="lineNum">    2511 </span>            :     : type(criteria.type), maxCount(criteria.max_iter), epsilon(criteria.epsilon) {}
<span class="lineNum">    2512 </span>            : inline TermCriteria::operator CvTermCriteria() const
<span class="lineNum">    2513 </span>            : { return cvTermCriteria(type, maxCount, epsilon); }
<span class="lineNum">    2514 </span>            : 
<span class="lineNum">    2515 </span>            : inline uchar* LineIterator::operator *() { return ptr; }
<span class="lineNum">    2516 </span>            : inline LineIterator&amp; LineIterator::operator ++()
<span class="lineNum">    2517 </span>            : {
<span class="lineNum">    2518 </span>            :     int mask = err &lt; 0 ? -1 : 0;
<span class="lineNum">    2519 </span>            :     err += minusDelta + (plusDelta &amp; mask);
<span class="lineNum">    2520 </span>            :     ptr += minusStep + (plusStep &amp; mask);
<span class="lineNum">    2521 </span>            :     return *this;
<span class="lineNum">    2522 </span>            : }
<span class="lineNum">    2523 </span>            : inline LineIterator LineIterator::operator ++(int)
<span class="lineNum">    2524 </span>            : {
<span class="lineNum">    2525 </span>            :     LineIterator it = *this;
<span class="lineNum">    2526 </span>            :     ++(*this);
<span class="lineNum">    2527 </span>            :     return it;
<span class="lineNum">    2528 </span>            : }
<span class="lineNum">    2529 </span>            : inline Point LineIterator::pos() const
<span class="lineNum">    2530 </span>            : {
<span class="lineNum">    2531 </span>            :     Point p;
<span class="lineNum">    2532 </span>            :     p.y = (int)((ptr - ptr0)/step);
<span class="lineNum">    2533 </span>            :     p.x = (int)(((ptr - ptr0) - p.y*step)/elemSize);
<span class="lineNum">    2534 </span>            :     return p;
<span class="lineNum">    2535 </span>            : }
<span class="lineNum">    2536 </span>            : 
<span class="lineNum">    2537 </span>            : /////////////////////////////// AutoBuffer ////////////////////////////////////////
<span class="lineNum">    2538 </span>            : 
<span class="lineNum">    2539 </span>            : template&lt;typename _Tp, size_t fixed_size&gt; inline AutoBuffer&lt;_Tp, fixed_size&gt;::AutoBuffer()
<span class="lineNum">    2540 </span>            : {
<span class="lineNum">    2541 </span>            :     ptr = buf;
<span class="lineNum">    2542 </span>            :     size = fixed_size;
<span class="lineNum">    2543 </span>            : }
<span class="lineNum">    2544 </span>            : 
<span class="lineNum">    2545 </span>            : template&lt;typename _Tp, size_t fixed_size&gt; inline AutoBuffer&lt;_Tp, fixed_size&gt;::AutoBuffer(size_t _size)
<span class="lineNum">    2546 </span>            : {
<span class="lineNum">    2547 </span>            :     ptr = buf;
<span class="lineNum">    2548 </span>            :     size = fixed_size;
<span class="lineNum">    2549 </span>            :     allocate(_size);
<span class="lineNum">    2550 </span>            : }
<span class="lineNum">    2551 </span>            : 
<span class="lineNum">    2552 </span>            : template&lt;typename _Tp, size_t fixed_size&gt; inline AutoBuffer&lt;_Tp, fixed_size&gt;::~AutoBuffer()
<span class="lineNum">    2553 </span>            : { deallocate(); }
<span class="lineNum">    2554 </span>            : 
<span class="lineNum">    2555 </span>            : template&lt;typename _Tp, size_t fixed_size&gt; inline void AutoBuffer&lt;_Tp, fixed_size&gt;::allocate(size_t _size)
<span class="lineNum">    2556 </span>            : {
<span class="lineNum">    2557 </span>            :     if(_size &lt;= size)
<span class="lineNum">    2558 </span>            :         return;
<span class="lineNum">    2559 </span>            :     deallocate();
<span class="lineNum">    2560 </span>            :     if(_size &gt; fixed_size)
<span class="lineNum">    2561 </span>            :     {
<span class="lineNum">    2562 </span>            :         ptr = cv::allocate&lt;_Tp&gt;(_size);
<span class="lineNum">    2563 </span>            :         size = _size;
<span class="lineNum">    2564 </span>            :     }
<span class="lineNum">    2565 </span>            : }
<span class="lineNum">    2566 </span>            : 
<span class="lineNum">    2567 </span>            : template&lt;typename _Tp, size_t fixed_size&gt; inline void AutoBuffer&lt;_Tp, fixed_size&gt;::deallocate()
<span class="lineNum">    2568 </span>            : {
<span class="lineNum">    2569 </span>            :     if( ptr != buf )
<span class="lineNum">    2570 </span>            :     {
<span class="lineNum">    2571 </span>            :         cv::deallocate&lt;_Tp&gt;(ptr, size);
<span class="lineNum">    2572 </span>            :         ptr = buf;
<span class="lineNum">    2573 </span>            :         size = fixed_size;
<span class="lineNum">    2574 </span>            :     }
<span class="lineNum">    2575 </span>            : }
<span class="lineNum">    2576 </span>            : 
<span class="lineNum">    2577 </span>            : template&lt;typename _Tp, size_t fixed_size&gt; inline AutoBuffer&lt;_Tp, fixed_size&gt;::operator _Tp* ()
<span class="lineNum">    2578 </span>            : { return ptr; }
<span class="lineNum">    2579 </span>            : 
<span class="lineNum">    2580 </span>            : template&lt;typename _Tp, size_t fixed_size&gt; inline AutoBuffer&lt;_Tp, fixed_size&gt;::operator const _Tp* () const
<span class="lineNum">    2581 </span>            : { return ptr; }
<span class="lineNum">    2582 </span>            : 
<span class="lineNum">    2583 </span>            : template&lt;typename _Tp, size_t fixed_size&gt; inline size_t AutoBuffer&lt;_Tp, fixed_size&gt;::getSize() const
<span class="lineNum">    2584 </span>            : { return size; }
<span class="lineNum">    2585 </span>            : 
<span class="lineNum">    2586 </span>            : 
<span class="lineNum">    2587 </span>            : /////////////////////////////////// Ptr ////////////////////////////////////////
<span class="lineNum">    2588 </span>            : 
<span class="lineNum">    2589 </span>            : template&lt;typename _Tp&gt; inline Ptr&lt;_Tp&gt;::Ptr() : obj(0), refcount(0) {}
<span class="lineNum">    2590 </span>            : template&lt;typename _Tp&gt; inline Ptr&lt;_Tp&gt;::Ptr(_Tp* _obj) : obj(_obj)
<span class="lineNum">    2591 </span>            : {
<span class="lineNum">    2592 </span>            :     if(obj)
<span class="lineNum">    2593 </span>            :     {
<span class="lineNum">    2594 </span>            :         refcount = (_Atomic_word*)fastMalloc(sizeof(*refcount));
<span class="lineNum">    2595 </span>            :         *refcount = 1;
<span class="lineNum">    2596 </span>            :     }
<span class="lineNum">    2597 </span>            :     else
<span class="lineNum">    2598 </span>            :         refcount = 0;
<span class="lineNum">    2599 </span>            : }
<span class="lineNum">    2600 </span>            : 
<span class="lineNum">    2601 </span>            : template&lt;typename _Tp&gt; inline void Ptr&lt;_Tp&gt;::addref()
<span class="lineNum">    2602 </span>            : { if( refcount ) CV_XADD(refcount, 1); }
<span class="lineNum">    2603 </span>            : 
<span class="lineNum">    2604 </span>            : template&lt;typename _Tp&gt; inline void Ptr&lt;_Tp&gt;::release()
<span class="lineNum">    2605 </span>            : {
<span class="lineNum">    2606 </span>            :     if( refcount &amp;&amp; CV_XADD(refcount, -1) == 1 )
<span class="lineNum">    2607 </span>            :     {
<span class="lineNum">    2608 </span>            :         delete_obj();
<span class="lineNum">    2609 </span>            :         fastFree(refcount);
<span class="lineNum">    2610 </span>            :     }
<span class="lineNum">    2611 </span>            :     refcount = 0;
<span class="lineNum">    2612 </span>            :     obj = 0;
<span class="lineNum">    2613 </span>            : }
<span class="lineNum">    2614 </span>            : 
<span class="lineNum">    2615 </span>            : template&lt;typename _Tp&gt; inline void Ptr&lt;_Tp&gt;::delete_obj()
<span class="lineNum">    2616 </span>            : {
<span class="lineNum">    2617 </span>            :     if( obj ) delete obj;
<span class="lineNum">    2618 </span>            : }
<span class="lineNum">    2619 </span>            : 
<span class="lineNum">    2620 </span>            : template&lt;typename _Tp&gt; inline Ptr&lt;_Tp&gt;::~Ptr() { release(); }
<span class="lineNum">    2621 </span>            : 
<span class="lineNum">    2622 </span>            : template&lt;typename _Tp&gt; inline Ptr&lt;_Tp&gt;::Ptr(const Ptr&lt;_Tp&gt;&amp; _ptr)
<span class="lineNum">    2623 </span>            : {
<span class="lineNum">    2624 </span>            :     obj = _ptr.obj;
<span class="lineNum">    2625 </span>            :     refcount = _ptr.refcount;
<span class="lineNum">    2626 </span>            :     addref();
<span class="lineNum">    2627 </span>            : }
<span class="lineNum">    2628 </span>            : 
<span class="lineNum">    2629 </span>            : template&lt;typename _Tp&gt; inline Ptr&lt;_Tp&gt;&amp; Ptr&lt;_Tp&gt;::operator = (const Ptr&lt;_Tp&gt;&amp; _ptr)
<span class="lineNum">    2630 </span>            : {
<span class="lineNum">    2631 </span>            :     _Atomic_word* _refcount = _ptr.refcount;
<span class="lineNum">    2632 </span>            :     if( _refcount )
<span class="lineNum">    2633 </span>            :         CV_XADD(_refcount, 1);
<span class="lineNum">    2634 </span>            :     release();
<span class="lineNum">    2635 </span>            :     obj = _ptr.obj;
<span class="lineNum">    2636 </span>            :     refcount = _refcount;
<span class="lineNum">    2637 </span>            :     return *this;
<span class="lineNum">    2638 </span>            : }
<span class="lineNum">    2639 </span>            : 
<span class="lineNum">    2640 </span>            : template&lt;typename _Tp&gt; inline _Tp* Ptr&lt;_Tp&gt;::operator -&gt; () { return obj; }
<span class="lineNum">    2641 </span>            : template&lt;typename _Tp&gt; inline const _Tp* Ptr&lt;_Tp&gt;::operator -&gt; () const { return obj; }
<span class="lineNum">    2642 </span>            : 
<span class="lineNum">    2643 </span>            : template&lt;typename _Tp&gt; inline Ptr&lt;_Tp&gt;::operator _Tp* () { return obj; }
<span class="lineNum">    2644 </span>            : template&lt;typename _Tp&gt; inline Ptr&lt;_Tp&gt;::operator const _Tp*() const { return obj; }
<span class="lineNum">    2645 </span>            : 
<span class="lineNum">    2646 </span>            : template&lt;typename _Tp&gt; inline bool Ptr&lt;_Tp&gt;::empty() const { return obj == 0; }
<span class="lineNum">    2647 </span>            : 
<span class="lineNum">    2648 </span>            : template&lt;typename _Tp&gt; template&lt;typename _Tp2&gt; Ptr&lt;_Tp&gt;::Ptr(const Ptr&lt;_Tp2&gt;&amp; p)
<span class="lineNum">    2649 </span>            :     : obj(0), refcount(0)
<span class="lineNum">    2650 </span>            : {
<span class="lineNum">    2651 </span>            :     if (p.empty())
<span class="lineNum">    2652 </span>            :         return;
<span class="lineNum">    2653 </span>            : 
<span class="lineNum">    2654 </span>            :     _Tp* p_casted = dynamic_cast&lt;_Tp*&gt;(p.obj);
<span class="lineNum">    2655 </span>            :     if (!p_casted)
<span class="lineNum">    2656 </span>            :         return;
<span class="lineNum">    2657 </span>            : 
<span class="lineNum">    2658 </span>            :     obj = p_casted;
<span class="lineNum">    2659 </span>            :     refcount = p.refcount;
<span class="lineNum">    2660 </span>            :     addref();
<span class="lineNum">    2661 </span>            : }
<span class="lineNum">    2662 </span>            : 
<span class="lineNum">    2663 </span>            : template&lt;typename _Tp&gt; template&lt;typename _Tp2&gt; inline Ptr&lt;_Tp2&gt; Ptr&lt;_Tp&gt;::ptr()
<span class="lineNum">    2664 </span>            : {
<span class="lineNum">    2665 </span>            :     Ptr&lt;_Tp2&gt; p;
<span class="lineNum">    2666 </span>            :     if( !obj )
<span class="lineNum">    2667 </span>            :         return p;
<span class="lineNum">    2668 </span>            : 
<span class="lineNum">    2669 </span>            :     _Tp2* obj_casted = dynamic_cast&lt;_Tp2*&gt;(obj);
<span class="lineNum">    2670 </span>            :     if (!obj_casted)
<span class="lineNum">    2671 </span>            :         return p;
<span class="lineNum">    2672 </span>            : 
<span class="lineNum">    2673 </span>            :     if( refcount )
<span class="lineNum">    2674 </span>            :         CV_XADD(refcount, 1);
<span class="lineNum">    2675 </span>            : 
<span class="lineNum">    2676 </span>            :     p.obj = obj_casted;
<span class="lineNum">    2677 </span>            :     p.refcount = refcount;
<span class="lineNum">    2678 </span>            :     return p;
<span class="lineNum">    2679 </span>            : }
<span class="lineNum">    2680 </span>            : 
<span class="lineNum">    2681 </span>            : template&lt;typename _Tp&gt; template&lt;typename _Tp2&gt; inline const Ptr&lt;_Tp2&gt; Ptr&lt;_Tp&gt;::ptr() const
<span class="lineNum">    2682 </span>            : {
<span class="lineNum">    2683 </span>            :     Ptr&lt;_Tp2&gt; p;
<span class="lineNum">    2684 </span>            :     if( !obj )
<span class="lineNum">    2685 </span>            :         return p;
<span class="lineNum">    2686 </span>            : 
<span class="lineNum">    2687 </span>            :     _Tp2* obj_casted = dynamic_cast&lt;_Tp2*&gt;(obj);
<span class="lineNum">    2688 </span>            :     if (!obj_casted)
<span class="lineNum">    2689 </span>            :         return p;
<span class="lineNum">    2690 </span>            : 
<span class="lineNum">    2691 </span>            :     if( refcount )
<span class="lineNum">    2692 </span>            :         CV_XADD(refcount, 1);
<span class="lineNum">    2693 </span>            : 
<span class="lineNum">    2694 </span>            :     p.obj = obj_casted;
<span class="lineNum">    2695 </span>            :     p.refcount = refcount;
<span class="lineNum">    2696 </span>            :     return p;
<span class="lineNum">    2697 </span>            : }
<span class="lineNum">    2698 </span>            : 
<span class="lineNum">    2699 </span>            : //// specializied implementations of Ptr::delete_obj() for classic OpenCV types
<span class="lineNum">    2700 </span>            : 
<span class="lineNum">    2701 </span>            : template&lt;&gt; CV_EXPORTS void Ptr&lt;CvMat&gt;::delete_obj();
<span class="lineNum">    2702 </span>            : template&lt;&gt; CV_EXPORTS void Ptr&lt;IplImage&gt;::delete_obj();
<span class="lineNum">    2703 </span>            : template&lt;&gt; CV_EXPORTS void Ptr&lt;CvMatND&gt;::delete_obj();
<span class="lineNum">    2704 </span>            : template&lt;&gt; CV_EXPORTS void Ptr&lt;CvSparseMat&gt;::delete_obj();
<span class="lineNum">    2705 </span>            : template&lt;&gt; CV_EXPORTS void Ptr&lt;CvMemStorage&gt;::delete_obj();
<span class="lineNum">    2706 </span>            : template&lt;&gt; CV_EXPORTS void Ptr&lt;CvFileStorage&gt;::delete_obj();
<span class="lineNum">    2707 </span>            : 
<span class="lineNum">    2708 </span>            : //////////////////////////////////////// XML &amp; YAML I/O ////////////////////////////////////
<span class="lineNum">    2709 </span>            : 
<span class="lineNum">    2710 </span>            : CV_EXPORTS_W void write( FileStorage&amp; fs, const string&amp; name, int value );
<span class="lineNum">    2711 </span>            : CV_EXPORTS_W void write( FileStorage&amp; fs, const string&amp; name, float value );
<span class="lineNum">    2712 </span>            : CV_EXPORTS_W void write( FileStorage&amp; fs, const string&amp; name, double value );
<span class="lineNum">    2713 </span>            : CV_EXPORTS_W void write( FileStorage&amp; fs, const string&amp; name, const string&amp; value );
<span class="lineNum">    2714 </span>            : 
<span class="lineNum">    2715 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const _Tp&amp; value)
<span class="lineNum">    2716 </span>            : { write(fs, string(), value); }
<span class="lineNum">    2717 </span>            : 
<span class="lineNum">    2718 </span>            : CV_EXPORTS void writeScalar( FileStorage&amp; fs, int value );
<span class="lineNum">    2719 </span>            : CV_EXPORTS void writeScalar( FileStorage&amp; fs, float value );
<span class="lineNum">    2720 </span>            : CV_EXPORTS void writeScalar( FileStorage&amp; fs, double value );
<span class="lineNum">    2721 </span>            : CV_EXPORTS void writeScalar( FileStorage&amp; fs, const string&amp; value );
<span class="lineNum">    2722 </span>            : 
<span class="lineNum">    2723 </span>            : template&lt;&gt; inline void write( FileStorage&amp; fs, const int&amp; value )
<span class="lineNum">    2724 </span>            : {
<span class="lineNum">    2725 </span>            :     writeScalar(fs, value);
<span class="lineNum">    2726 </span>            : }
<span class="lineNum">    2727 </span>            : 
<span class="lineNum">    2728 </span>            : template&lt;&gt; inline void write( FileStorage&amp; fs, const float&amp; value )
<span class="lineNum">    2729 </span>            : {
<span class="lineNum">    2730 </span>            :     writeScalar(fs, value);
<span class="lineNum">    2731 </span>            : }
<span class="lineNum">    2732 </span>            : 
<span class="lineNum">    2733 </span>            : template&lt;&gt; inline void write( FileStorage&amp; fs, const double&amp; value )
<span class="lineNum">    2734 </span>            : {
<span class="lineNum">    2735 </span>            :     writeScalar(fs, value);
<span class="lineNum">    2736 </span>            : }
<span class="lineNum">    2737 </span>            : 
<span class="lineNum">    2738 </span>            : template&lt;&gt; inline void write( FileStorage&amp; fs, const string&amp; value )
<span class="lineNum">    2739 </span>            : {
<span class="lineNum">    2740 </span>            :     writeScalar(fs, value);
<span class="lineNum">    2741 </span>            : }
<span class="lineNum">    2742 </span>            : 
<span class="lineNum">    2743 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const Point_&lt;_Tp&gt;&amp; pt )
<span class="lineNum">    2744 </span>            : {
<span class="lineNum">    2745 </span>            :     write(fs, pt.x);
<span class="lineNum">    2746 </span>            :     write(fs, pt.y);
<span class="lineNum">    2747 </span>            : }
<span class="lineNum">    2748 </span>            : 
<span class="lineNum">    2749 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const Point3_&lt;_Tp&gt;&amp; pt )
<span class="lineNum">    2750 </span>            : {
<span class="lineNum">    2751 </span>            :     write(fs, pt.x);
<span class="lineNum">    2752 </span>            :     write(fs, pt.y);
<span class="lineNum">    2753 </span>            :     write(fs, pt.z);
<span class="lineNum">    2754 </span>            : }
<span class="lineNum">    2755 </span>            : 
<span class="lineNum">    2756 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const Size_&lt;_Tp&gt;&amp; sz )
<span class="lineNum">    2757 </span>            : {
<span class="lineNum">    2758 </span>            :     write(fs, sz.width);
<span class="lineNum">    2759 </span>            :     write(fs, sz.height);
<span class="lineNum">    2760 </span>            : }
<span class="lineNum">    2761 </span>            : 
<span class="lineNum">    2762 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const Complex&lt;_Tp&gt;&amp; c )
<span class="lineNum">    2763 </span>            : {
<span class="lineNum">    2764 </span>            :     write(fs, c.re);
<span class="lineNum">    2765 </span>            :     write(fs, c.im);
<span class="lineNum">    2766 </span>            : }
<span class="lineNum">    2767 </span>            : 
<span class="lineNum">    2768 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const Rect_&lt;_Tp&gt;&amp; r )
<span class="lineNum">    2769 </span>            : {
<span class="lineNum">    2770 </span>            :     write(fs, r.x);
<span class="lineNum">    2771 </span>            :     write(fs, r.y);
<span class="lineNum">    2772 </span>            :     write(fs, r.width);
<span class="lineNum">    2773 </span>            :     write(fs, r.height);
<span class="lineNum">    2774 </span>            : }
<span class="lineNum">    2775 </span>            : 
<span class="lineNum">    2776 </span>            : template&lt;typename _Tp, int cn&gt; inline void write(FileStorage&amp; fs, const Vec&lt;_Tp, cn&gt;&amp; v )
<span class="lineNum">    2777 </span>            : {
<span class="lineNum">    2778 </span>            :     for(int i = 0; i &lt; cn; i++)
<span class="lineNum">    2779 </span>            :         write(fs, v.val[i]);
<span class="lineNum">    2780 </span>            : }
<span class="lineNum">    2781 </span>            : 
<span class="lineNum">    2782 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const Scalar_&lt;_Tp&gt;&amp; s )
<span class="lineNum">    2783 </span>            : {
<span class="lineNum">    2784 </span>            :     write(fs, s.val[0]);
<span class="lineNum">    2785 </span>            :     write(fs, s.val[1]);
<span class="lineNum">    2786 </span>            :     write(fs, s.val[2]);
<span class="lineNum">    2787 </span>            :     write(fs, s.val[3]);
<span class="lineNum">    2788 </span>            : }
<span class="lineNum">    2789 </span>            : 
<span class="lineNum">    2790 </span>            : inline void write(FileStorage&amp; fs, const Range&amp; r )
<span class="lineNum">    2791 </span>            : {
<span class="lineNum">    2792 </span>            :     write(fs, r.start);
<span class="lineNum">    2793 </span>            :     write(fs, r.end);
<span class="lineNum">    2794 </span>            : }
<span class="lineNum">    2795 </span>            : 
<span class="lineNum">    2796 </span>            : class CV_EXPORTS WriteStructContext
<span class="lineNum">    2797 </span>            : {
<span class="lineNum">    2798 </span>            : public:
<span class="lineNum">    2799 </span>            :     WriteStructContext(FileStorage&amp; _fs, const string&amp; name,
<span class="lineNum">    2800 </span>            :         int flags, const string&amp; typeName=string());
<span class="lineNum">    2801 </span>            :     ~WriteStructContext();
<span class="lineNum">    2802 </span>            :     FileStorage* fs;
<span class="lineNum">    2803 </span>            : };
<span class="lineNum">    2804 </span>            : 
<span class="lineNum">    2805 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const string&amp; name, const Point_&lt;_Tp&gt;&amp; pt )
<span class="lineNum">    2806 </span>            : {
<span class="lineNum">    2807 </span>            :     WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
<span class="lineNum">    2808 </span>            :     write(fs, pt.x);
<span class="lineNum">    2809 </span>            :     write(fs, pt.y);
<span class="lineNum">    2810 </span>            : }
<span class="lineNum">    2811 </span>            : 
<span class="lineNum">    2812 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const string&amp; name, const Point3_&lt;_Tp&gt;&amp; pt )
<span class="lineNum">    2813 </span>            : {
<span class="lineNum">    2814 </span>            :     WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
<span class="lineNum">    2815 </span>            :     write(fs, pt.x);
<span class="lineNum">    2816 </span>            :     write(fs, pt.y);
<span class="lineNum">    2817 </span>            :     write(fs, pt.z);
<span class="lineNum">    2818 </span>            : }
<span class="lineNum">    2819 </span>            : 
<span class="lineNum">    2820 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const string&amp; name, const Size_&lt;_Tp&gt;&amp; sz )
<span class="lineNum">    2821 </span>            : {
<span class="lineNum">    2822 </span>            :     WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
<span class="lineNum">    2823 </span>            :     write(fs, sz.width);
<span class="lineNum">    2824 </span>            :     write(fs, sz.height);
<span class="lineNum">    2825 </span>            : }
<span class="lineNum">    2826 </span>            : 
<span class="lineNum">    2827 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const string&amp; name, const Complex&lt;_Tp&gt;&amp; c )
<span class="lineNum">    2828 </span>            : {
<span class="lineNum">    2829 </span>            :     WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
<span class="lineNum">    2830 </span>            :     write(fs, c.re);
<span class="lineNum">    2831 </span>            :     write(fs, c.im);
<span class="lineNum">    2832 </span>            : }
<span class="lineNum">    2833 </span>            : 
<span class="lineNum">    2834 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const string&amp; name, const Rect_&lt;_Tp&gt;&amp; r )
<span class="lineNum">    2835 </span>            : {
<span class="lineNum">    2836 </span>            :     WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
<span class="lineNum">    2837 </span>            :     write(fs, r.x);
<span class="lineNum">    2838 </span>            :     write(fs, r.y);
<span class="lineNum">    2839 </span>            :     write(fs, r.width);
<span class="lineNum">    2840 </span>            :     write(fs, r.height);
<span class="lineNum">    2841 </span>            : }
<span class="lineNum">    2842 </span>            : 
<span class="lineNum">    2843 </span>            : template&lt;typename _Tp, int cn&gt; inline void write(FileStorage&amp; fs, const string&amp; name, const Vec&lt;_Tp, cn&gt;&amp; v )
<span class="lineNum">    2844 </span>            : {
<span class="lineNum">    2845 </span>            :     WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
<span class="lineNum">    2846 </span>            :     for(int i = 0; i &lt; cn; i++)
<span class="lineNum">    2847 </span>            :         write(fs, v.val[i]);
<span class="lineNum">    2848 </span>            : }
<span class="lineNum">    2849 </span>            : 
<span class="lineNum">    2850 </span>            : template&lt;typename _Tp&gt; inline void write(FileStorage&amp; fs, const string&amp; name, const Scalar_&lt;_Tp&gt;&amp; s )
<span class="lineNum">    2851 </span>            : {
<span class="lineNum">    2852 </span>            :     WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
<span class="lineNum">    2853 </span>            :     write(fs, s.val[0]);
<span class="lineNum">    2854 </span>            :     write(fs, s.val[1]);
<span class="lineNum">    2855 </span>            :     write(fs, s.val[2]);
<span class="lineNum">    2856 </span>            :     write(fs, s.val[3]);
<span class="lineNum">    2857 </span>            : }
<span class="lineNum">    2858 </span>            : 
<span class="lineNum">    2859 </span>            : inline void write(FileStorage&amp; fs, const string&amp; name, const Range&amp; r )
<span class="lineNum">    2860 </span>            : {
<span class="lineNum">    2861 </span>            :     WriteStructContext ws(fs, name, CV_NODE_SEQ+CV_NODE_FLOW);
<span class="lineNum">    2862 </span>            :     write(fs, r.start);
<span class="lineNum">    2863 </span>            :     write(fs, r.end);
<span class="lineNum">    2864 </span>            : }
<span class="lineNum">    2865 </span>            : 
<span class="lineNum">    2866 </span>            : template&lt;typename _Tp, int numflag&gt; class VecWriterProxy
<span class="lineNum">    2867 </span>            : {
<span class="lineNum">    2868 </span>            : public:
<span class="lineNum">    2869 </span>            :     VecWriterProxy( FileStorage* _fs ) : fs(_fs) {}
<span class="lineNum">    2870 </span>            :     void operator()(const vector&lt;_Tp&gt;&amp; vec) const
<span class="lineNum">    2871 </span>            :     {
<span class="lineNum">    2872 </span>            :         size_t i, count = vec.size();
<span class="lineNum">    2873 </span>            :         for( i = 0; i &lt; count; i++ )
<span class="lineNum">    2874 </span>            :             write( *fs, vec[i] );
<span class="lineNum">    2875 </span>            :     }
<span class="lineNum">    2876 </span>            :     FileStorage* fs;
<span class="lineNum">    2877 </span>            : };
<span class="lineNum">    2878 </span>            : 
<span class="lineNum">    2879 </span>            : template&lt;typename _Tp&gt; class VecWriterProxy&lt;_Tp,1&gt;
<span class="lineNum">    2880 </span>            : {
<span class="lineNum">    2881 </span>            : public:
<span class="lineNum">    2882 </span>            :     VecWriterProxy( FileStorage* _fs ) : fs(_fs) {}
<span class="lineNum">    2883 </span>            :     void operator()(const vector&lt;_Tp&gt;&amp; vec) const
<span class="lineNum">    2884 </span>            :     {
<span class="lineNum">    2885 </span>            :         int _fmt = DataType&lt;_Tp&gt;::fmt;
<span class="lineNum">    2886 </span>            :         char fmt[] = { (char)((_fmt&gt;&gt;8)+'1'), (char)_fmt, '\0' };
<span class="lineNum">    2887 </span>            :         fs-&gt;writeRaw( string(fmt), !vec.empty() ? (uchar*)&amp;vec[0] : 0, vec.size()*sizeof(_Tp) );
<span class="lineNum">    2888 </span>            :     }
<span class="lineNum">    2889 </span>            :     FileStorage* fs;
<span class="lineNum">    2890 </span>            : };
<span class="lineNum">    2891 </span>            : 
<span class="lineNum">    2892 </span>            : template&lt;typename _Tp&gt; static inline void write( FileStorage&amp; fs, const vector&lt;_Tp&gt;&amp; vec )
<span class="lineNum">    2893 </span>            : {
<span class="lineNum">    2894 </span>            :     VecWriterProxy&lt;_Tp, DataType&lt;_Tp&gt;::fmt != 0&gt; w(&amp;fs);
<span class="lineNum">    2895 </span>            :     w(vec);
<span class="lineNum">    2896 </span>            : }
<span class="lineNum">    2897 </span>            : 
<span class="lineNum">    2898 </span>            : template&lt;typename _Tp&gt; static inline void write( FileStorage&amp; fs, const string&amp; name,
<span class="lineNum">    2899 </span>            :                                                 const vector&lt;_Tp&gt;&amp; vec )
<span class="lineNum">    2900 </span>            : {
<span class="lineNum">    2901 </span>            :     WriteStructContext ws(fs, name, CV_NODE_SEQ+(DataType&lt;_Tp&gt;::fmt != 0 ? CV_NODE_FLOW : 0));
<span class="lineNum">    2902 </span>            :     write(fs, vec);
<span class="lineNum">    2903 </span>            : }
<span class="lineNum">    2904 </span>            : 
<span class="lineNum">    2905 </span>            : CV_EXPORTS_W void write( FileStorage&amp; fs, const string&amp; name, const Mat&amp; value );
<span class="lineNum">    2906 </span>            : CV_EXPORTS void write( FileStorage&amp; fs, const string&amp; name, const SparseMat&amp; value );
<span class="lineNum">    2907 </span>            : 
<span class="lineNum">    2908 </span>            : template&lt;typename _Tp&gt; static inline FileStorage&amp; operator &lt;&lt; (FileStorage&amp; fs, const _Tp&amp; value)
<span class="lineNum">    2909 </span>            : {
<span class="lineNum">    2910 </span>            :     if( !fs.isOpened() )
<span class="lineNum">    2911 </span>            :         return fs;
<span class="lineNum">    2912 </span>            :     if( fs.state == FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP )
<span class="lineNum">    2913 </span>            :         CV_Error( CV_StsError, &quot;No element name has been given&quot; );
<span class="lineNum">    2914 </span>            :     write( fs, fs.elname, value );
<span class="lineNum">    2915 </span>            :     if( fs.state &amp; FileStorage::INSIDE_MAP )
<span class="lineNum">    2916 </span>            :         fs.state = FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP;
<span class="lineNum">    2917 </span>            :     return fs;
<span class="lineNum">    2918 </span>            : }
<span class="lineNum">    2919 </span>            : 
<span class="lineNum">    2920 </span>            : CV_EXPORTS FileStorage&amp; operator &lt;&lt; (FileStorage&amp; fs, const string&amp; str);
<span class="lineNum">    2921 </span>            : 
<span class="lineNum">    2922 </span>            : static inline FileStorage&amp; operator &lt;&lt; (FileStorage&amp; fs, const char* str)
<span class="lineNum">    2923 </span>            : { return (fs &lt;&lt; string(str)); }
<span class="lineNum">    2924 </span>            : 
<span class="lineNum">    2925 </span>            : static inline FileStorage&amp; operator &lt;&lt; (FileStorage&amp; fs, char* value)
<span class="lineNum">    2926 </span>            : { return (fs &lt;&lt; string(value)); }
<span class="lineNum">    2927 </span>            : 
<span class="lineNum">    2928 </span>            : inline FileNode::FileNode() : fs(0), node(0) {}
<span class="lineNum">    2929 </span>            : inline FileNode::FileNode(const CvFileStorage* _fs, const CvFileNode* _node)
<span class="lineNum">    2930 </span>            :     : fs(_fs), node(_node) {}
<span class="lineNum">    2931 </span>            : 
<span class="lineNum">    2932 </span>            : inline FileNode::FileNode(const FileNode&amp; _node) : fs(_node.fs), node(_node.node) {}
<span class="lineNum">    2933 </span>            : 
<span class="lineNum">    2934 </span>            : inline int FileNode::type() const { return !node ? NONE : (node-&gt;tag &amp; TYPE_MASK); }
<span class="lineNum">    2935 </span>            : inline bool FileNode::empty() const { return node == 0; }
<span class="lineNum">    2936 </span>            : inline bool FileNode::isNone() const { return type() == NONE; }
<span class="lineNum">    2937 </span>            : inline bool FileNode::isSeq() const { return type() == SEQ; }
<span class="lineNum">    2938 </span>            : inline bool FileNode::isMap() const { return type() == MAP; }
<span class="lineNum">    2939 </span>            : inline bool FileNode::isInt() const { return type() == INT; }
<span class="lineNum">    2940 </span>            : inline bool FileNode::isReal() const { return type() == REAL; }
<span class="lineNum">    2941 </span>            : inline bool FileNode::isString() const { return type() == STR; }
<span class="lineNum">    2942 </span>            : inline bool FileNode::isNamed() const { return !node ? false : (node-&gt;tag &amp; NAMED) != 0; }
<span class="lineNum">    2943 </span>            : inline size_t FileNode::size() const
<span class="lineNum">    2944 </span>            : {
<span class="lineNum">    2945 </span>            :     int t = type();
<span class="lineNum">    2946 </span>            :     return t == MAP ? (size_t)((CvSet*)node-&gt;data.map)-&gt;active_count :
<span class="lineNum">    2947 </span>            :         t == SEQ ? (size_t)node-&gt;data.seq-&gt;total : (size_t)!isNone();
<span class="lineNum">    2948 </span>            : }
<span class="lineNum">    2949 </span>            : 
<span class="lineNum">    2950 </span>            : inline CvFileNode* FileNode::operator *() { return (CvFileNode*)node; }
<span class="lineNum">    2951 </span>            : inline const CvFileNode* FileNode::operator* () const { return node; }
<span class="lineNum">    2952 </span>            : 
<span class="lineNum">    2953 </span>            : static inline void read(const FileNode&amp; node, int&amp; value, int default_value)
<span class="lineNum">    2954 </span>            : {
<span class="lineNum">    2955 </span>            :     value = !node.node ? default_value :
<span class="lineNum">    2956 </span>            :     CV_NODE_IS_INT(node.node-&gt;tag) ? node.node-&gt;data.i :
<span class="lineNum">    2957 </span>            :     CV_NODE_IS_REAL(node.node-&gt;tag) ? cvRound(node.node-&gt;data.f) : 0x7fffffff;
<span class="lineNum">    2958 </span>            : }
<span class="lineNum">    2959 </span>            : 
<span class="lineNum">    2960 </span>            : static inline void read(const FileNode&amp; node, bool&amp; value, bool default_value)
<span class="lineNum">    2961 </span>            : {
<span class="lineNum">    2962 </span>            :     int temp; read(node, temp, (int)default_value);
<span class="lineNum">    2963 </span>            :     value = temp != 0;
<span class="lineNum">    2964 </span>            : }
<span class="lineNum">    2965 </span>            : 
<span class="lineNum">    2966 </span>            : static inline void read(const FileNode&amp; node, uchar&amp; value, uchar default_value)
<span class="lineNum">    2967 </span>            : {
<span class="lineNum">    2968 </span>            :     int temp; read(node, temp, (int)default_value);
<span class="lineNum">    2969 </span>            :     value = saturate_cast&lt;uchar&gt;(temp);
<span class="lineNum">    2970 </span>            : }
<span class="lineNum">    2971 </span>            : 
<span class="lineNum">    2972 </span>            : static inline void read(const FileNode&amp; node, schar&amp; value, schar default_value)
<span class="lineNum">    2973 </span>            : {
<span class="lineNum">    2974 </span>            :     int temp; read(node, temp, (int)default_value);
<span class="lineNum">    2975 </span>            :     value = saturate_cast&lt;schar&gt;(temp);
<span class="lineNum">    2976 </span>            : }
<span class="lineNum">    2977 </span>            : 
<span class="lineNum">    2978 </span>            : static inline void read(const FileNode&amp; node, ushort&amp; value, ushort default_value)
<span class="lineNum">    2979 </span>            : {
<span class="lineNum">    2980 </span>            :     int temp; read(node, temp, (int)default_value);
<span class="lineNum">    2981 </span>            :     value = saturate_cast&lt;ushort&gt;(temp);
<span class="lineNum">    2982 </span>            : }
<span class="lineNum">    2983 </span>            : 
<span class="lineNum">    2984 </span>            : static inline void read(const FileNode&amp; node, short&amp; value, short default_value)
<span class="lineNum">    2985 </span>            : {
<span class="lineNum">    2986 </span>            :     int temp; read(node, temp, (int)default_value);
<span class="lineNum">    2987 </span>            :     value = saturate_cast&lt;short&gt;(temp);
<span class="lineNum">    2988 </span>            : }
<span class="lineNum">    2989 </span>            : 
<span class="lineNum">    2990 </span>            : static inline void read(const FileNode&amp; node, float&amp; value, float default_value)
<span class="lineNum">    2991 </span>            : {
<span class="lineNum">    2992 </span>            :     value = !node.node ? default_value :
<span class="lineNum">    2993 </span>            :         CV_NODE_IS_INT(node.node-&gt;tag) ? (float)node.node-&gt;data.i :
<span class="lineNum">    2994 </span>            :         CV_NODE_IS_REAL(node.node-&gt;tag) ? (float)node.node-&gt;data.f : 1e30f;
<span class="lineNum">    2995 </span>            : }
<span class="lineNum">    2996 </span>            : 
<span class="lineNum">    2997 </span>            : static inline void read(const FileNode&amp; node, double&amp; value, double default_value)
<span class="lineNum">    2998 </span>            : {
<span class="lineNum">    2999 </span>            :     value = !node.node ? default_value :
<span class="lineNum">    3000 </span>            :         CV_NODE_IS_INT(node.node-&gt;tag) ? (double)node.node-&gt;data.i :
<span class="lineNum">    3001 </span>            :         CV_NODE_IS_REAL(node.node-&gt;tag) ? node.node-&gt;data.f : 1e300;
<span class="lineNum">    3002 </span>            : }
<span class="lineNum">    3003 </span>            : 
<span class="lineNum">    3004 </span>            : static inline void read(const FileNode&amp; node, string&amp; value, const string&amp; default_value)
<span class="lineNum">    3005 </span>            : {
<span class="lineNum">    3006 </span>            :     value = !node.node ? default_value : CV_NODE_IS_STRING(node.node-&gt;tag) ? string(node.node-&gt;data.str.ptr) : string(&quot;&quot;);
<span class="lineNum">    3007 </span>            : }
<span class="lineNum">    3008 </span>            : 
<span class="lineNum">    3009 </span>            : template&lt;typename _Tp&gt; static inline void read(const FileNode&amp; node, Point_&lt;_Tp&gt;&amp; value, const Point_&lt;_Tp&gt;&amp; default_value)
<span class="lineNum">    3010 </span>            : {
<span class="lineNum">    3011 </span>            :     vector&lt;_Tp&gt; temp; FileNodeIterator it = node.begin(); it &gt;&gt; temp;
<span class="lineNum">    3012 </span>            :     value = temp.size() != 2 ? default_value : Point_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(temp[0]), saturate_cast&lt;_Tp&gt;(temp[1]));
<span class="lineNum">    3013 </span>            : }
<span class="lineNum">    3014 </span>            : 
<span class="lineNum">    3015 </span>            : template&lt;typename _Tp&gt; static inline void read(const FileNode&amp; node, Point3_&lt;_Tp&gt;&amp; value, const Point3_&lt;_Tp&gt;&amp; default_value)
<span class="lineNum">    3016 </span>            : {
<span class="lineNum">    3017 </span>            :     vector&lt;_Tp&gt; temp; FileNodeIterator it = node.begin(); it &gt;&gt; temp;
<span class="lineNum">    3018 </span>            :     value = temp.size() != 3 ? default_value : Point3_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(temp[0]), saturate_cast&lt;_Tp&gt;(temp[1]),
<span class="lineNum">    3019 </span>            :                                                             saturate_cast&lt;_Tp&gt;(temp[2]));
<span class="lineNum">    3020 </span>            : }
<span class="lineNum">    3021 </span>            : 
<span class="lineNum">    3022 </span>            : template&lt;typename _Tp&gt; static inline void read(const FileNode&amp; node, Size_&lt;_Tp&gt;&amp; value, const Size_&lt;_Tp&gt;&amp; default_value)
<span class="lineNum">    3023 </span>            : {
<span class="lineNum">    3024 </span>            :     vector&lt;_Tp&gt; temp; FileNodeIterator it = node.begin(); it &gt;&gt; temp;
<span class="lineNum">    3025 </span>            :     value = temp.size() != 2 ? default_value : Size_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(temp[0]), saturate_cast&lt;_Tp&gt;(temp[1]));
<span class="lineNum">    3026 </span>            : }
<span class="lineNum">    3027 </span>            : 
<span class="lineNum">    3028 </span>            : template&lt;typename _Tp&gt; static inline void read(const FileNode&amp; node, Complex&lt;_Tp&gt;&amp; value, const Complex&lt;_Tp&gt;&amp; default_value)
<span class="lineNum">    3029 </span>            : {
<span class="lineNum">    3030 </span>            :     vector&lt;_Tp&gt; temp; FileNodeIterator it = node.begin(); it &gt;&gt; temp;
<span class="lineNum">    3031 </span>            :     value = temp.size() != 2 ? default_value : Complex&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(temp[0]), saturate_cast&lt;_Tp&gt;(temp[1]));
<span class="lineNum">    3032 </span>            : }
<span class="lineNum">    3033 </span>            : 
<span class="lineNum">    3034 </span>            : template&lt;typename _Tp&gt; static inline void read(const FileNode&amp; node, Rect_&lt;_Tp&gt;&amp; value, const Rect_&lt;_Tp&gt;&amp; default_value)
<span class="lineNum">    3035 </span>            : {
<span class="lineNum">    3036 </span>            :     vector&lt;_Tp&gt; temp; FileNodeIterator it = node.begin(); it &gt;&gt; temp;
<span class="lineNum">    3037 </span>            :     value = temp.size() != 4 ? default_value : Rect_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(temp[0]), saturate_cast&lt;_Tp&gt;(temp[1]),
<span class="lineNum">    3038 </span>            :                                                           saturate_cast&lt;_Tp&gt;(temp[2]), saturate_cast&lt;_Tp&gt;(temp[3]));
<span class="lineNum">    3039 </span>            : }
<span class="lineNum">    3040 </span>            : 
<span class="lineNum">    3041 </span>            : template&lt;typename _Tp, int cn&gt; static inline void read(const FileNode&amp; node, Vec&lt;_Tp, cn&gt;&amp; value, const Vec&lt;_Tp, cn&gt;&amp; default_value)
<span class="lineNum">    3042 </span>            : {
<span class="lineNum">    3043 </span>            :     vector&lt;_Tp&gt; temp; FileNodeIterator it = node.begin(); it &gt;&gt; temp;
<span class="lineNum">    3044 </span>            :     value = temp.size() != cn ? default_value : Vec&lt;_Tp, cn&gt;(&amp;temp[0]);
<span class="lineNum">    3045 </span>            : }
<span class="lineNum">    3046 </span>            : 
<span class="lineNum">    3047 </span>            : template&lt;typename _Tp&gt; static inline void read(const FileNode&amp; node, Scalar_&lt;_Tp&gt;&amp; value, const Scalar_&lt;_Tp&gt;&amp; default_value)
<span class="lineNum">    3048 </span>            : {
<span class="lineNum">    3049 </span>            :     vector&lt;_Tp&gt; temp; FileNodeIterator it = node.begin(); it &gt;&gt; temp;
<span class="lineNum">    3050 </span>            :     value = temp.size() != 4 ? default_value : Scalar_&lt;_Tp&gt;(saturate_cast&lt;_Tp&gt;(temp[0]), saturate_cast&lt;_Tp&gt;(temp[1]),
<span class="lineNum">    3051 </span>            :                                                             saturate_cast&lt;_Tp&gt;(temp[2]), saturate_cast&lt;_Tp&gt;(temp[3]));
<span class="lineNum">    3052 </span>            : }
<span class="lineNum">    3053 </span>            : 
<span class="lineNum">    3054 </span>            : static inline void read(const FileNode&amp; node, Range&amp; value, const Range&amp; default_value)
<span class="lineNum">    3055 </span>            : {
<span class="lineNum">    3056 </span>            :     Point2i temp(value.start, value.end); const Point2i default_temp = Point2i(default_value.start, default_value.end);
<span class="lineNum">    3057 </span>            :     read(node, temp, default_temp);
<span class="lineNum">    3058 </span>            :     value.start = temp.x; value.end = temp.y;
<span class="lineNum">    3059 </span>            : }
<span class="lineNum">    3060 </span>            : 
<span class="lineNum">    3061 </span>            : CV_EXPORTS_W void read(const FileNode&amp; node, Mat&amp; mat, const Mat&amp; default_mat=Mat() );
<span class="lineNum">    3062 </span>            : CV_EXPORTS void read(const FileNode&amp; node, SparseMat&amp; mat, const SparseMat&amp; default_mat=SparseMat() );
<span class="lineNum">    3063 </span>            : 
<span class="lineNum">    3064 </span>            : inline FileNode::operator int() const
<span class="lineNum">    3065 </span>            : {
<span class="lineNum">    3066 </span>            :     int value;
<span class="lineNum">    3067 </span>            :     read(*this, value, 0);
<span class="lineNum">    3068 </span>            :     return value;
<span class="lineNum">    3069 </span>            : }
<span class="lineNum">    3070 </span>            : inline FileNode::operator float() const
<span class="lineNum">    3071 </span>            : {
<span class="lineNum">    3072 </span>            :     float value;
<span class="lineNum">    3073 </span>            :     read(*this, value, 0.f);
<span class="lineNum">    3074 </span>            :     return value;
<span class="lineNum">    3075 </span>            : }
<span class="lineNum">    3076 </span>            : inline FileNode::operator double() const
<span class="lineNum">    3077 </span>            : {
<span class="lineNum">    3078 </span>            :     double value;
<span class="lineNum">    3079 </span>            :     read(*this, value, 0.);
<span class="lineNum">    3080 </span>            :     return value;
<span class="lineNum">    3081 </span>            : }
<span class="lineNum">    3082 </span>            : inline FileNode::operator string() const
<span class="lineNum">    3083 </span>            : {
<span class="lineNum">    3084 </span>            :     string value;
<span class="lineNum">    3085 </span>            :     read(*this, value, value);
<span class="lineNum">    3086 </span>            :     return value;
<span class="lineNum">    3087 </span>            : }
<span class="lineNum">    3088 </span>            : 
<span class="lineNum">    3089 </span>            : inline void FileNode::readRaw( const string&amp; fmt, uchar* vec, size_t len ) const
<span class="lineNum">    3090 </span>            : {
<span class="lineNum">    3091 </span>            :     begin().readRaw( fmt, vec, len );
<span class="lineNum">    3092 </span>            : }
<span class="lineNum">    3093 </span>            : 
<span class="lineNum">    3094 </span>            : template&lt;typename _Tp, int numflag&gt; class VecReaderProxy
<span class="lineNum">    3095 </span>            : {
<span class="lineNum">    3096 </span>            : public:
<span class="lineNum">    3097 </span>            :     VecReaderProxy( FileNodeIterator* _it ) : it(_it) {}
<span class="lineNum">    3098 </span>            :     void operator()(vector&lt;_Tp&gt;&amp; vec, size_t count) const
<span class="lineNum">    3099 </span>            :     {
<span class="lineNum">    3100 </span>            :         count = std::min(count, it-&gt;remaining);
<span class="lineNum">    3101 </span>            :         vec.resize(count);
<span class="lineNum">    3102 </span>            :         for( size_t i = 0; i &lt; count; i++, ++(*it) )
<span class="lineNum">    3103 </span>            :             read(**it, vec[i], _Tp());
<span class="lineNum">    3104 </span>            :     }
<span class="lineNum">    3105 </span>            :     FileNodeIterator* it;
<span class="lineNum">    3106 </span>            : };
<span class="lineNum">    3107 </span>            : 
<span class="lineNum">    3108 </span>            : template&lt;typename _Tp&gt; class VecReaderProxy&lt;_Tp,1&gt;
<span class="lineNum">    3109 </span>            : {
<span class="lineNum">    3110 </span>            : public:
<span class="lineNum">    3111 </span>            :     VecReaderProxy( FileNodeIterator* _it ) : it(_it) {}
<span class="lineNum">    3112 </span>            :     void operator()(vector&lt;_Tp&gt;&amp; vec, size_t count) const
<span class="lineNum">    3113 </span>            :     {
<span class="lineNum">    3114 </span>            :         size_t remaining = it-&gt;remaining, cn = DataType&lt;_Tp&gt;::channels;
<span class="lineNum">    3115 </span>            :         int _fmt = DataType&lt;_Tp&gt;::fmt;
<span class="lineNum">    3116 </span>            :         char fmt[] = { (char)((_fmt&gt;&gt;8)+'1'), (char)_fmt, '\0' };
<span class="lineNum">    3117 </span>            :         size_t remaining1 = remaining/cn;
<span class="lineNum">    3118 </span>            :         count = count &lt; remaining1 ? count : remaining1;
<span class="lineNum">    3119 </span>            :         vec.resize(count);
<span class="lineNum">    3120 </span>            :         it-&gt;readRaw( string(fmt), !vec.empty() ? (uchar*)&amp;vec[0] : 0, count*sizeof(_Tp) );
<span class="lineNum">    3121 </span>            :     }
<span class="lineNum">    3122 </span>            :     FileNodeIterator* it;
<span class="lineNum">    3123 </span>            : };
<span class="lineNum">    3124 </span>            : 
<span class="lineNum">    3125 </span>            : template&lt;typename _Tp&gt; static inline void
<span class="lineNum">    3126 </span>            : read( FileNodeIterator&amp; it, vector&lt;_Tp&gt;&amp; vec, size_t maxCount=(size_t)INT_MAX )
<span class="lineNum">    3127 </span>            : {
<span class="lineNum">    3128 </span>            :     VecReaderProxy&lt;_Tp, DataType&lt;_Tp&gt;::fmt != 0&gt; r(&amp;it);
<span class="lineNum">    3129 </span>            :     r(vec, maxCount);
<span class="lineNum">    3130 </span>            : }
<span class="lineNum">    3131 </span>            : 
<span class="lineNum">    3132 </span>            : template&lt;typename _Tp&gt; static inline void
<span class="lineNum">    3133 </span>            : read( const FileNode&amp; node, vector&lt;_Tp&gt;&amp; vec, const vector&lt;_Tp&gt;&amp; default_value=vector&lt;_Tp&gt;() )
<span class="lineNum">    3134 </span>            : {
<span class="lineNum">    3135 </span>            :     if(!node.node)
<span class="lineNum">    3136 </span>            :         vec = default_value;
<span class="lineNum">    3137 </span>            :     else
<span class="lineNum">    3138 </span>            :     {
<span class="lineNum">    3139 </span>            :         FileNodeIterator it = node.begin();
<span class="lineNum">    3140 </span>            :         read( it, vec );
<span class="lineNum">    3141 </span>            :     }
<span class="lineNum">    3142 </span>            : }
<span class="lineNum">    3143 </span>            : 
<span class="lineNum">    3144 </span>            : inline FileNodeIterator FileNode::begin() const
<span class="lineNum">    3145 </span>            : {
<span class="lineNum">    3146 </span>            :     return FileNodeIterator(fs, node);
<span class="lineNum">    3147 </span>            : }
<span class="lineNum">    3148 </span>            : 
<span class="lineNum">    3149 </span>            : inline FileNodeIterator FileNode::end() const
<span class="lineNum">    3150 </span>            : {
<span class="lineNum">    3151 </span>            :     return FileNodeIterator(fs, node, size());
<span class="lineNum">    3152 </span>            : }
<span class="lineNum">    3153 </span>            : 
<span class="lineNum">    3154 </span>            : inline FileNode FileNodeIterator::operator *() const
<span class="lineNum">    3155 </span>            : { return FileNode(fs, (const CvFileNode*)(void*)reader.ptr); }
<span class="lineNum">    3156 </span>            : 
<span class="lineNum">    3157 </span>            : inline FileNode FileNodeIterator::operator -&gt;() const
<span class="lineNum">    3158 </span>            : { return FileNode(fs, (const CvFileNode*)(void*)reader.ptr); }
<span class="lineNum">    3159 </span>            : 
<span class="lineNum">    3160 </span>            : template&lt;typename _Tp&gt; static inline FileNodeIterator&amp; operator &gt;&gt; (FileNodeIterator&amp; it, _Tp&amp; value)
<span class="lineNum">    3161 </span>            : { read( *it, value, _Tp()); return ++it; }
<span class="lineNum">    3162 </span>            : 
<span class="lineNum">    3163 </span>            : template&lt;typename _Tp&gt; static inline
<span class="lineNum">    3164 </span>            : FileNodeIterator&amp; operator &gt;&gt; (FileNodeIterator&amp; it, vector&lt;_Tp&gt;&amp; vec)
<span class="lineNum">    3165 </span>            : {
<span class="lineNum">    3166 </span>            :     VecReaderProxy&lt;_Tp, DataType&lt;_Tp&gt;::fmt != 0&gt; r(&amp;it);
<span class="lineNum">    3167 </span>            :     r(vec, (size_t)INT_MAX);
<span class="lineNum">    3168 </span>            :     return it;
<span class="lineNum">    3169 </span>            : }
<span class="lineNum">    3170 </span>            : 
<span class="lineNum">    3171 </span>            : template&lt;typename _Tp&gt; static inline void operator &gt;&gt; (const FileNode&amp; n, _Tp&amp; value)
<span class="lineNum">    3172 </span>            : { read( n, value, _Tp()); }
<span class="lineNum">    3173 </span>            : 
<span class="lineNum">    3174 </span>            : template&lt;typename _Tp&gt; static inline void operator &gt;&gt; (const FileNode&amp; n, vector&lt;_Tp&gt;&amp; vec)
<span class="lineNum">    3175 </span>            : { FileNodeIterator it = n.begin(); it &gt;&gt; vec; }
<span class="lineNum">    3176 </span>            : 
<span class="lineNum">    3177 </span>            : static inline bool operator == (const FileNodeIterator&amp; it1, const FileNodeIterator&amp; it2)
<span class="lineNum">    3178 </span>            : {
<span class="lineNum">    3179 </span>            :     return it1.fs == it2.fs &amp;&amp; it1.container == it2.container &amp;&amp;
<span class="lineNum">    3180 </span>            :         it1.reader.ptr == it2.reader.ptr &amp;&amp; it1.remaining == it2.remaining;
<span class="lineNum">    3181 </span>            : }
<span class="lineNum">    3182 </span>            : 
<span class="lineNum">    3183 </span>            : static inline bool operator != (const FileNodeIterator&amp; it1, const FileNodeIterator&amp; it2)
<span class="lineNum">    3184 </span>            : {
<span class="lineNum">    3185 </span>            :     return !(it1 == it2);
<span class="lineNum">    3186 </span>            : }
<span class="lineNum">    3187 </span>            : 
<span class="lineNum">    3188 </span>            : static inline ptrdiff_t operator - (const FileNodeIterator&amp; it1, const FileNodeIterator&amp; it2)
<span class="lineNum">    3189 </span>            : {
<span class="lineNum">    3190 </span>            :     return it2.remaining - it1.remaining;
<span class="lineNum">    3191 </span>            : }
<span class="lineNum">    3192 </span>            : 
<span class="lineNum">    3193 </span>            : static inline bool operator &lt; (const FileNodeIterator&amp; it1, const FileNodeIterator&amp; it2)
<span class="lineNum">    3194 </span>            : {
<span class="lineNum">    3195 </span>            :     return it1.remaining &gt; it2.remaining;
<span class="lineNum">    3196 </span>            : }
<span class="lineNum">    3197 </span>            : 
<span class="lineNum">    3198 </span>            : inline FileNode FileStorage::getFirstTopLevelNode() const
<span class="lineNum">    3199 </span>            : {
<span class="lineNum">    3200 </span>            :     FileNode r = root();
<span class="lineNum">    3201 </span>            :     FileNodeIterator it = r.begin();
<span class="lineNum">    3202 </span>            :     return it != r.end() ? *it : FileNode();
<span class="lineNum">    3203 </span>            : }
<span class="lineNum">    3204 </span>            : 
<span class="lineNum">    3205 </span>            : //////////////////////////////////////// Various algorithms ////////////////////////////////////
<span class="lineNum">    3206 </span>            : 
<span class="lineNum">    3207 </span>            : template&lt;typename _Tp&gt; static inline _Tp gcd(_Tp a, _Tp b)
<span class="lineNum">    3208 </span>            : {
<span class="lineNum">    3209 </span>            :     if( a &lt; b )
<span class="lineNum">    3210 </span>            :         std::swap(a, b);
<span class="lineNum">    3211 </span>            :     while( b &gt; 0 )
<span class="lineNum">    3212 </span>            :     {
<span class="lineNum">    3213 </span>            :         _Tp r = a % b;
<span class="lineNum">    3214 </span>            :         a = b;
<span class="lineNum">    3215 </span>            :         b = r;
<span class="lineNum">    3216 </span>            :     }
<span class="lineNum">    3217 </span>            :     return a;
<span class="lineNum">    3218 </span>            : }
<span class="lineNum">    3219 </span>            : 
<span class="lineNum">    3220 </span>            : /****************************************************************************************\
<span class="lineNum">    3221 </span>            : 
<span class="lineNum">    3222 </span>            :   Generic implementation of QuickSort algorithm
<span class="lineNum">    3223 </span>            :   Use it as: vector&lt;_Tp&gt; a; ... sort(a,&lt;less_than_predictor&gt;);
<span class="lineNum">    3224 </span>            : 
<span class="lineNum">    3225 </span>            :   The current implementation was derived from *BSD system qsort():
<span class="lineNum">    3226 </span>            : 
<span class="lineNum">    3227 </span>            :     * Copyright (c) 1992, 1993
<span class="lineNum">    3228 </span>            :     *  The Regents of the University of California.  All rights reserved.
<span class="lineNum">    3229 </span>            :     *
<span class="lineNum">    3230 </span>            :     * Redistribution and use in source and binary forms, with or without
<span class="lineNum">    3231 </span>            :     * modification, are permitted provided that the following conditions
<span class="lineNum">    3232 </span>            :     * are met:
<span class="lineNum">    3233 </span>            :     * 1. Redistributions of source code must retain the above copyright
<span class="lineNum">    3234 </span>            :     *    notice, this list of conditions and the following disclaimer.
<span class="lineNum">    3235 </span>            :     * 2. Redistributions in binary form must reproduce the above copyright
<span class="lineNum">    3236 </span>            :     *    notice, this list of conditions and the following disclaimer in the
<span class="lineNum">    3237 </span>            :     *    documentation and/or other materials provided with the distribution.
<span class="lineNum">    3238 </span>            :     * 3. All advertising materials mentioning features or use of this software
<span class="lineNum">    3239 </span>            :     *    must display the following acknowledgement:
<span class="lineNum">    3240 </span>            :     *  This product includes software developed by the University of
<span class="lineNum">    3241 </span>            :     *  California, Berkeley and its contributors.
<span class="lineNum">    3242 </span>            :     * 4. Neither the name of the University nor the names of its contributors
<span class="lineNum">    3243 </span>            :     *    may be used to endorse or promote products derived from this software
<span class="lineNum">    3244 </span>            :     *    without specific prior written permission.
<span class="lineNum">    3245 </span>            :     *
<span class="lineNum">    3246 </span>            :     * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
<span class="lineNum">    3247 </span>            :     * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<span class="lineNum">    3248 </span>            :     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
<span class="lineNum">    3249 </span>            :     * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
<span class="lineNum">    3250 </span>            :     * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<span class="lineNum">    3251 </span>            :     * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
<span class="lineNum">    3252 </span>            :     * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
<span class="lineNum">    3253 </span>            :     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
<span class="lineNum">    3254 </span>            :     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
<span class="lineNum">    3255 </span>            :     * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
<span class="lineNum">    3256 </span>            :     * SUCH DAMAGE.
<span class="lineNum">    3257 </span>            : 
<span class="lineNum">    3258 </span>            : \****************************************************************************************/
<span class="lineNum">    3259 </span>            : 
<span class="lineNum">    3260 </span>            : template&lt;typename _Tp, class _LT&gt; void sort( vector&lt;_Tp&gt;&amp; vec, _LT LT=_LT() )
<span class="lineNum">    3261 </span>            : {
<span class="lineNum">    3262 </span>            :     int isort_thresh = 7;
<span class="lineNum">    3263 </span>            :     int sp = 0;
<span class="lineNum">    3264 </span>            : 
<span class="lineNum">    3265 </span>            :     struct
<span class="lineNum">    3266 </span>            :     {
<span class="lineNum">    3267 </span>            :         _Tp *lb;
<span class="lineNum">    3268 </span>            :         _Tp *ub;
<span class="lineNum">    3269 </span>            :     } stack[48];
<span class="lineNum">    3270 </span>            : 
<span class="lineNum">    3271 </span>            :     size_t total = vec.size();
<span class="lineNum">    3272 </span>            : 
<span class="lineNum">    3273 </span>            :     if( total &lt;= 1 )
<span class="lineNum">    3274 </span>            :         return;
<span class="lineNum">    3275 </span>            : 
<span class="lineNum">    3276 </span>            :     _Tp* arr = &amp;vec[0];
<span class="lineNum">    3277 </span>            :     stack[0].lb = arr;
<span class="lineNum">    3278 </span>            :     stack[0].ub = arr + (total - 1);
<span class="lineNum">    3279 </span>            : 
<span class="lineNum">    3280 </span>            :     while( sp &gt;= 0 )
<span class="lineNum">    3281 </span>            :     {
<span class="lineNum">    3282 </span>            :         _Tp* left = stack[sp].lb;
<span class="lineNum">    3283 </span>            :         _Tp* right = stack[sp--].ub;
<span class="lineNum">    3284 </span>            : 
<span class="lineNum">    3285 </span>            :         for(;;)
<span class="lineNum">    3286 </span>            :         {
<span class="lineNum">    3287 </span>            :             int i, n = (int)(right - left) + 1, m;
<span class="lineNum">    3288 </span>            :             _Tp* ptr;
<span class="lineNum">    3289 </span>            :             _Tp* ptr2;
<span class="lineNum">    3290 </span>            : 
<span class="lineNum">    3291 </span>            :             if( n &lt;= isort_thresh )
<span class="lineNum">    3292 </span>            :             {
<span class="lineNum">    3293 </span>            :             insert_sort:
<span class="lineNum">    3294 </span>            :                 for( ptr = left + 1; ptr &lt;= right; ptr++ )
<span class="lineNum">    3295 </span>            :                 {
<span class="lineNum">    3296 </span>            :                     for( ptr2 = ptr; ptr2 &gt; left &amp;&amp; LT(ptr2[0],ptr2[-1]); ptr2--)
<span class="lineNum">    3297 </span>            :                         std::swap( ptr2[0], ptr2[-1] );
<span class="lineNum">    3298 </span>            :                 }
<span class="lineNum">    3299 </span>            :                 break;
<span class="lineNum">    3300 </span>            :             }
<span class="lineNum">    3301 </span>            :             else
<span class="lineNum">    3302 </span>            :             {
<span class="lineNum">    3303 </span>            :                 _Tp* left0;
<span class="lineNum">    3304 </span>            :                 _Tp* left1;
<span class="lineNum">    3305 </span>            :                 _Tp* right0;
<span class="lineNum">    3306 </span>            :                 _Tp* right1;
<span class="lineNum">    3307 </span>            :                 _Tp* pivot;
<span class="lineNum">    3308 </span>            :                 _Tp* a;
<span class="lineNum">    3309 </span>            :                 _Tp* b;
<span class="lineNum">    3310 </span>            :                 _Tp* c;
<span class="lineNum">    3311 </span>            :                 int swap_cnt = 0;
<span class="lineNum">    3312 </span>            : 
<span class="lineNum">    3313 </span>            :                 left0 = left;
<span class="lineNum">    3314 </span>            :                 right0 = right;
<span class="lineNum">    3315 </span>            :                 pivot = left + (n/2);
<span class="lineNum">    3316 </span>            : 
<span class="lineNum">    3317 </span>            :                 if( n &gt; 40 )
<span class="lineNum">    3318 </span>            :                 {
<span class="lineNum">    3319 </span>            :                     int d = n / 8;
<span class="lineNum">    3320 </span>            :                     a = left, b = left + d, c = left + 2*d;
<span class="lineNum">    3321 </span>            :                     left = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a))
<span class="lineNum">    3322 </span>            :                                       : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c));
<span class="lineNum">    3323 </span>            : 
<span class="lineNum">    3324 </span>            :                     a = pivot - d, b = pivot, c = pivot + d;
<span class="lineNum">    3325 </span>            :                     pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a))
<span class="lineNum">    3326 </span>            :                                       : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c));
<span class="lineNum">    3327 </span>            : 
<span class="lineNum">    3328 </span>            :                     a = right - 2*d, b = right - d, c = right;
<span class="lineNum">    3329 </span>            :                     right = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a))
<span class="lineNum">    3330 </span>            :                                       : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c));
<span class="lineNum">    3331 </span>            :                 }
<span class="lineNum">    3332 </span>            : 
<span class="lineNum">    3333 </span>            :                 a = left, b = pivot, c = right;
<span class="lineNum">    3334 </span>            :                 pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a))
<span class="lineNum">    3335 </span>            :                                    : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c));
<span class="lineNum">    3336 </span>            :                 if( pivot != left0 )
<span class="lineNum">    3337 </span>            :                 {
<span class="lineNum">    3338 </span>            :                     std::swap( *pivot, *left0 );
<span class="lineNum">    3339 </span>            :                     pivot = left0;
<span class="lineNum">    3340 </span>            :                 }
<span class="lineNum">    3341 </span>            :                 left = left1 = left0 + 1;
<span class="lineNum">    3342 </span>            :                 right = right1 = right0;
<span class="lineNum">    3343 </span>            : 
<span class="lineNum">    3344 </span>            :                 for(;;)
<span class="lineNum">    3345 </span>            :                 {
<span class="lineNum">    3346 </span>            :                     while( left &lt;= right &amp;&amp; !LT(*pivot, *left) )
<span class="lineNum">    3347 </span>            :                     {
<span class="lineNum">    3348 </span>            :                         if( !LT(*left, *pivot) )
<span class="lineNum">    3349 </span>            :                         {
<span class="lineNum">    3350 </span>            :                             if( left &gt; left1 )
<span class="lineNum">    3351 </span>            :                                 std::swap( *left1, *left );
<span class="lineNum">    3352 </span>            :                             swap_cnt = 1;
<span class="lineNum">    3353 </span>            :                             left1++;
<span class="lineNum">    3354 </span>            :                         }
<span class="lineNum">    3355 </span>            :                         left++;
<span class="lineNum">    3356 </span>            :                     }
<span class="lineNum">    3357 </span>            : 
<span class="lineNum">    3358 </span>            :                     while( left &lt;= right &amp;&amp; !LT(*right, *pivot) )
<span class="lineNum">    3359 </span>            :                     {
<span class="lineNum">    3360 </span>            :                         if( !LT(*pivot, *right) )
<span class="lineNum">    3361 </span>            :                         {
<span class="lineNum">    3362 </span>            :                             if( right &lt; right1 )
<span class="lineNum">    3363 </span>            :                                 std::swap( *right1, *right );
<span class="lineNum">    3364 </span>            :                             swap_cnt = 1;
<span class="lineNum">    3365 </span>            :                             right1--;
<span class="lineNum">    3366 </span>            :                         }
<span class="lineNum">    3367 </span>            :                         right--;
<span class="lineNum">    3368 </span>            :                     }
<span class="lineNum">    3369 </span>            : 
<span class="lineNum">    3370 </span>            :                     if( left &gt; right )
<span class="lineNum">    3371 </span>            :                         break;
<span class="lineNum">    3372 </span>            :                     std::swap( *left, *right );
<span class="lineNum">    3373 </span>            :                     swap_cnt = 1;
<span class="lineNum">    3374 </span>            :                     left++;
<span class="lineNum">    3375 </span>            :                     right--;
<span class="lineNum">    3376 </span>            :                 }
<span class="lineNum">    3377 </span>            : 
<span class="lineNum">    3378 </span>            :                 if( swap_cnt == 0 )
<span class="lineNum">    3379 </span>            :                 {
<span class="lineNum">    3380 </span>            :                     left = left0, right = right0;
<span class="lineNum">    3381 </span>            :                     goto insert_sort;
<span class="lineNum">    3382 </span>            :                 }
<span class="lineNum">    3383 </span>            : 
<span class="lineNum">    3384 </span>            :                 n = std::min( (int)(left1 - left0), (int)(left - left1) );
<span class="lineNum">    3385 </span>            :                 for( i = 0; i &lt; n; i++ )
<span class="lineNum">    3386 </span>            :                     std::swap( left0[i], left[i-n] );
<span class="lineNum">    3387 </span>            : 
<span class="lineNum">    3388 </span>            :                 n = std::min( (int)(right0 - right1), (int)(right1 - right) );
<span class="lineNum">    3389 </span>            :                 for( i = 0; i &lt; n; i++ )
<span class="lineNum">    3390 </span>            :                     std::swap( left[i], right0[i-n+1] );
<span class="lineNum">    3391 </span>            :                 n = (int)(left - left1);
<span class="lineNum">    3392 </span>            :                 m = (int)(right1 - right);
<span class="lineNum">    3393 </span>            :                 if( n &gt; 1 )
<span class="lineNum">    3394 </span>            :                 {
<span class="lineNum">    3395 </span>            :                     if( m &gt; 1 )
<span class="lineNum">    3396 </span>            :                     {
<span class="lineNum">    3397 </span>            :                         if( n &gt; m )
<span class="lineNum">    3398 </span>            :                         {
<span class="lineNum">    3399 </span>            :                             stack[++sp].lb = left0;
<span class="lineNum">    3400 </span>            :                             stack[sp].ub = left0 + n - 1;
<span class="lineNum">    3401 </span>            :                             left = right0 - m + 1, right = right0;
<span class="lineNum">    3402 </span>            :                         }
<span class="lineNum">    3403 </span>            :                         else
<span class="lineNum">    3404 </span>            :                         {
<span class="lineNum">    3405 </span>            :                             stack[++sp].lb = right0 - m + 1;
<span class="lineNum">    3406 </span>            :                             stack[sp].ub = right0;
<span class="lineNum">    3407 </span>            :                             left = left0, right = left0 + n - 1;
<span class="lineNum">    3408 </span>            :                         }
<span class="lineNum">    3409 </span>            :                     }
<span class="lineNum">    3410 </span>            :                     else
<span class="lineNum">    3411 </span>            :                         left = left0, right = left0 + n - 1;
<span class="lineNum">    3412 </span>            :                 }
<span class="lineNum">    3413 </span>            :                 else if( m &gt; 1 )
<span class="lineNum">    3414 </span>            :                     left = right0 - m + 1, right = right0;
<span class="lineNum">    3415 </span>            :                 else
<span class="lineNum">    3416 </span>            :                     break;
<span class="lineNum">    3417 </span>            :             }
<span class="lineNum">    3418 </span>            :         }
<span class="lineNum">    3419 </span>            :     }
<span class="lineNum">    3420 </span>            : }
<span class="lineNum">    3421 </span>            : 
<span class="lineNum">    3422 </span>            : template&lt;typename _Tp&gt; class LessThan
<span class="lineNum">    3423 </span>            : {
<span class="lineNum">    3424 </span>            : public:
<span class="lineNum">    3425 </span>            :     bool operator()(const _Tp&amp; a, const _Tp&amp; b) const { return a &lt; b; }
<span class="lineNum">    3426 </span>            : };
<span class="lineNum">    3427 </span>            : 
<span class="lineNum">    3428 </span>            : template&lt;typename _Tp&gt; class GreaterEq
<span class="lineNum">    3429 </span>            : {
<span class="lineNum">    3430 </span>            : public:
<span class="lineNum">    3431 </span>            :     bool operator()(const _Tp&amp; a, const _Tp&amp; b) const { return a &gt;= b; }
<span class="lineNum">    3432 </span>            : };
<span class="lineNum">    3433 </span>            : 
<span class="lineNum">    3434 </span>            : template&lt;typename _Tp&gt; class LessThanIdx
<span class="lineNum">    3435 </span>            : {
<span class="lineNum">    3436 </span>            : public:
<span class="lineNum">    3437 </span>            :     LessThanIdx( const _Tp* _arr ) : arr(_arr) {}
<span class="lineNum">    3438 </span>            :     bool operator()(int a, int b) const { return arr[a] &lt; arr[b]; }
<span class="lineNum">    3439 </span>            :     const _Tp* arr;
<span class="lineNum">    3440 </span>            : };
<span class="lineNum">    3441 </span>            : 
<span class="lineNum">    3442 </span>            : template&lt;typename _Tp&gt; class GreaterEqIdx
<span class="lineNum">    3443 </span>            : {
<span class="lineNum">    3444 </span>            : public:
<span class="lineNum">    3445 </span>            :     GreaterEqIdx( const _Tp* _arr ) : arr(_arr) {}
<span class="lineNum">    3446 </span>            :     bool operator()(int a, int b) const { return arr[a] &gt;= arr[b]; }
<span class="lineNum">    3447 </span>            :     const _Tp* arr;
<span class="lineNum">    3448 </span>            : };
<span class="lineNum">    3449 </span>            : 
<span class="lineNum">    3450 </span>            : 
<span class="lineNum">    3451 </span>            : // This function splits the input sequence or set into one or more equivalence classes and
<span class="lineNum">    3452 </span>            : // returns the vector of labels - 0-based class indexes for each element.
<span class="lineNum">    3453 </span>            : // predicate(a,b) returns true if the two sequence elements certainly belong to the same class.
<span class="lineNum">    3454 </span>            : //
<span class="lineNum">    3455 </span>            : // The algorithm is described in &quot;Introduction to Algorithms&quot;
<span class="lineNum">    3456 </span>            : // by Cormen, Leiserson and Rivest, the chapter &quot;Data structures for disjoint sets&quot;
<span class="lineNum">    3457 </span>            : template&lt;typename _Tp, class _EqPredicate&gt; int
<span class="lineNum">    3458 </span>            : partition( const vector&lt;_Tp&gt;&amp; _vec, vector&lt;int&gt;&amp; labels,
<span class="lineNum">    3459 </span>            :            _EqPredicate predicate=_EqPredicate())
<span class="lineNum">    3460 </span>            : {
<span class="lineNum">    3461 </span>            :     int i, j, N = (int)_vec.size();
<span class="lineNum">    3462 </span>            :     const _Tp* vec = &amp;_vec[0];
<span class="lineNum">    3463 </span>            : 
<span class="lineNum">    3464 </span>            :     const int PARENT=0;
<span class="lineNum">    3465 </span>            :     const int RANK=1;
<span class="lineNum">    3466 </span>            : 
<span class="lineNum">    3467 </span>            :     vector&lt;int&gt; _nodes(N*2);
<span class="lineNum">    3468 </span>            :     int (*nodes)[2] = (int(*)[2])&amp;_nodes[0];
<span class="lineNum">    3469 </span>            : 
<span class="lineNum">    3470 </span>            :     // The first O(N) pass: create N single-vertex trees
<span class="lineNum">    3471 </span>            :     for(i = 0; i &lt; N; i++)
<span class="lineNum">    3472 </span>            :     {
<span class="lineNum">    3473 </span>            :         nodes[i][PARENT]=-1;
<span class="lineNum">    3474 </span>            :         nodes[i][RANK] = 0;
<span class="lineNum">    3475 </span>            :     }
<span class="lineNum">    3476 </span>            : 
<span class="lineNum">    3477 </span>            :     // The main O(N^2) pass: merge connected components
<span class="lineNum">    3478 </span>            :     for( i = 0; i &lt; N; i++ )
<span class="lineNum">    3479 </span>            :     {
<span class="lineNum">    3480 </span>            :         int root = i;
<span class="lineNum">    3481 </span>            : 
<span class="lineNum">    3482 </span>            :         // find root
<span class="lineNum">    3483 </span>            :         while( nodes[root][PARENT] &gt;= 0 )
<span class="lineNum">    3484 </span>            :             root = nodes[root][PARENT];
<span class="lineNum">    3485 </span>            : 
<span class="lineNum">    3486 </span>            :         for( j = 0; j &lt; N; j++ )
<span class="lineNum">    3487 </span>            :         {
<span class="lineNum">    3488 </span>            :             if( i == j || !predicate(vec[i], vec[j]))
<span class="lineNum">    3489 </span>            :                 continue;
<span class="lineNum">    3490 </span>            :             int root2 = j;
<span class="lineNum">    3491 </span>            : 
<span class="lineNum">    3492 </span>            :             while( nodes[root2][PARENT] &gt;= 0 )
<span class="lineNum">    3493 </span>            :                 root2 = nodes[root2][PARENT];
<span class="lineNum">    3494 </span>            : 
<span class="lineNum">    3495 </span>            :             if( root2 != root )
<span class="lineNum">    3496 </span>            :             {
<span class="lineNum">    3497 </span>            :                 // unite both trees
<span class="lineNum">    3498 </span>            :                 int rank = nodes[root][RANK], rank2 = nodes[root2][RANK];
<span class="lineNum">    3499 </span>            :                 if( rank &gt; rank2 )
<span class="lineNum">    3500 </span>            :                     nodes[root2][PARENT] = root;
<span class="lineNum">    3501 </span>            :                 else
<span class="lineNum">    3502 </span>            :                 {
<span class="lineNum">    3503 </span>            :                     nodes[root][PARENT] = root2;
<span class="lineNum">    3504 </span>            :                     nodes[root2][RANK] += rank == rank2;
<span class="lineNum">    3505 </span>            :                     root = root2;
<span class="lineNum">    3506 </span>            :                 }
<span class="lineNum">    3507 </span>            :                 assert( nodes[root][PARENT] &lt; 0 );
<span class="lineNum">    3508 </span>            : 
<span class="lineNum">    3509 </span>            :                 int k = j, parent;
<span class="lineNum">    3510 </span>            : 
<span class="lineNum">    3511 </span>            :                 // compress the path from node2 to root
<span class="lineNum">    3512 </span>            :                 while( (parent = nodes[k][PARENT]) &gt;= 0 )
<span class="lineNum">    3513 </span>            :                 {
<span class="lineNum">    3514 </span>            :                     nodes[k][PARENT] = root;
<span class="lineNum">    3515 </span>            :                     k = parent;
<span class="lineNum">    3516 </span>            :                 }
<span class="lineNum">    3517 </span>            : 
<span class="lineNum">    3518 </span>            :                 // compress the path from node to root
<span class="lineNum">    3519 </span>            :                 k = i;
<span class="lineNum">    3520 </span>            :                 while( (parent = nodes[k][PARENT]) &gt;= 0 )
<span class="lineNum">    3521 </span>            :                 {
<span class="lineNum">    3522 </span>            :                     nodes[k][PARENT] = root;
<span class="lineNum">    3523 </span>            :                     k = parent;
<span class="lineNum">    3524 </span>            :                 }
<span class="lineNum">    3525 </span>            :             }
<span class="lineNum">    3526 </span>            :         }
<span class="lineNum">    3527 </span>            :     }
<span class="lineNum">    3528 </span>            : 
<span class="lineNum">    3529 </span>            :     // Final O(N) pass: enumerate classes
<span class="lineNum">    3530 </span>            :     labels.resize(N);
<span class="lineNum">    3531 </span>            :     int nclasses = 0;
<span class="lineNum">    3532 </span>            : 
<span class="lineNum">    3533 </span>            :     for( i = 0; i &lt; N; i++ )
<span class="lineNum">    3534 </span>            :     {
<span class="lineNum">    3535 </span>            :         int root = i;
<span class="lineNum">    3536 </span>            :         while( nodes[root][PARENT] &gt;= 0 )
<span class="lineNum">    3537 </span>            :             root = nodes[root][PARENT];
<span class="lineNum">    3538 </span>            :         // re-use the rank as the class label
<span class="lineNum">    3539 </span>            :         if( nodes[root][RANK] &gt;= 0 )
<span class="lineNum">    3540 </span>            :             nodes[root][RANK] = ~nclasses++;
<span class="lineNum">    3541 </span>            :         labels[i] = ~nodes[root][RANK];
<span class="lineNum">    3542 </span>            :     }
<span class="lineNum">    3543 </span>            : 
<span class="lineNum">    3544 </span>            :     return nclasses;
<span class="lineNum">    3545 </span>            : }
<span class="lineNum">    3546 </span>            : 
<span class="lineNum">    3547 </span>            : 
<span class="lineNum">    3548 </span>            : //////////////////////////////////////////////////////////////////////////////
<span class="lineNum">    3549 </span>            : 
<span class="lineNum">    3550 </span>            : // bridge C++ =&gt; C Seq API
<span class="lineNum">    3551 </span>            : CV_EXPORTS schar*  seqPush( CvSeq* seq, const void* element=0);
<span class="lineNum">    3552 </span>            : CV_EXPORTS schar*  seqPushFront( CvSeq* seq, const void* element=0);
<span class="lineNum">    3553 </span>            : CV_EXPORTS void  seqPop( CvSeq* seq, void* element=0);
<span class="lineNum">    3554 </span>            : CV_EXPORTS void  seqPopFront( CvSeq* seq, void* element=0);
<span class="lineNum">    3555 </span>            : CV_EXPORTS void  seqPopMulti( CvSeq* seq, void* elements,
<span class="lineNum">    3556 </span>            :                               int count, int in_front=0 );
<span class="lineNum">    3557 </span>            : CV_EXPORTS void  seqRemove( CvSeq* seq, int index );
<span class="lineNum">    3558 </span>            : CV_EXPORTS void  clearSeq( CvSeq* seq );
<span class="lineNum">    3559 </span>            : CV_EXPORTS schar*  getSeqElem( const CvSeq* seq, int index );
<span class="lineNum">    3560 </span>            : CV_EXPORTS void  seqRemoveSlice( CvSeq* seq, CvSlice slice );
<span class="lineNum">    3561 </span>            : CV_EXPORTS void  seqInsertSlice( CvSeq* seq, int before_index, const CvArr* from_arr );
<span class="lineNum">    3562 </span>            : 
<span class="lineNum">    3563 </span>            : template&lt;typename _Tp&gt; inline Seq&lt;_Tp&gt;::Seq() : seq(0) {}
<span class="lineNum">    3564 </span>            : template&lt;typename _Tp&gt; inline Seq&lt;_Tp&gt;::Seq( const CvSeq* _seq ) : seq((CvSeq*)_seq)
<span class="lineNum">    3565 </span>            : {
<span class="lineNum">    3566 </span>            :     CV_Assert(!_seq || _seq-&gt;elem_size == sizeof(_Tp));
<span class="lineNum">    3567 </span>            : }
<span class="lineNum">    3568 </span>            : 
<span class="lineNum">    3569 </span>            : template&lt;typename _Tp&gt; inline Seq&lt;_Tp&gt;::Seq( MemStorage&amp; storage,
<span class="lineNum">    3570 </span>            :                                              int headerSize )
<span class="lineNum">    3571 </span>            : {
<span class="lineNum">    3572 </span>            :     CV_Assert(headerSize &gt;= (int)sizeof(CvSeq));
<span class="lineNum">    3573 </span>            :     seq = cvCreateSeq(DataType&lt;_Tp&gt;::type, headerSize, sizeof(_Tp), storage);
<span class="lineNum">    3574 </span>            : }
<span class="lineNum">    3575 </span>            : 
<span class="lineNum">    3576 </span>            : template&lt;typename _Tp&gt; inline _Tp&amp; Seq&lt;_Tp&gt;::operator [](int idx)
<span class="lineNum">    3577 </span>            : { return *(_Tp*)getSeqElem(seq, idx); }
<span class="lineNum">    3578 </span>            : 
<span class="lineNum">    3579 </span>            : template&lt;typename _Tp&gt; inline const _Tp&amp; Seq&lt;_Tp&gt;::operator [](int idx) const
<span class="lineNum">    3580 </span>            : { return *(_Tp*)getSeqElem(seq, idx); }
<span class="lineNum">    3581 </span>            : 
<span class="lineNum">    3582 </span>            : template&lt;typename _Tp&gt; inline SeqIterator&lt;_Tp&gt; Seq&lt;_Tp&gt;::begin() const
<span class="lineNum">    3583 </span>            : { return SeqIterator&lt;_Tp&gt;(*this); }
<span class="lineNum">    3584 </span>            : 
<span class="lineNum">    3585 </span>            : template&lt;typename _Tp&gt; inline SeqIterator&lt;_Tp&gt; Seq&lt;_Tp&gt;::end() const
<span class="lineNum">    3586 </span>            : { return SeqIterator&lt;_Tp&gt;(*this, true); }
<span class="lineNum">    3587 </span>            : 
<span class="lineNum">    3588 </span>            : template&lt;typename _Tp&gt; inline size_t Seq&lt;_Tp&gt;::size() const
<span class="lineNum">    3589 </span>            : { return seq ? seq-&gt;total : 0; }
<span class="lineNum">    3590 </span>            : 
<span class="lineNum">    3591 </span>            : template&lt;typename _Tp&gt; inline int Seq&lt;_Tp&gt;::type() const
<span class="lineNum">    3592 </span>            : { return seq ? CV_MAT_TYPE(seq-&gt;flags) : 0; }
<span class="lineNum">    3593 </span>            : 
<span class="lineNum">    3594 </span>            : template&lt;typename _Tp&gt; inline int Seq&lt;_Tp&gt;::depth() const
<span class="lineNum">    3595 </span>            : { return seq ? CV_MAT_DEPTH(seq-&gt;flags) : 0; }
<span class="lineNum">    3596 </span>            : 
<span class="lineNum">    3597 </span>            : template&lt;typename _Tp&gt; inline int Seq&lt;_Tp&gt;::channels() const
<span class="lineNum">    3598 </span>            : { return seq ? CV_MAT_CN(seq-&gt;flags) : 0; }
<span class="lineNum">    3599 </span>            : 
<span class="lineNum">    3600 </span>            : template&lt;typename _Tp&gt; inline size_t Seq&lt;_Tp&gt;::elemSize() const
<span class="lineNum">    3601 </span>            : { return seq ? seq-&gt;elem_size : 0; }
<span class="lineNum">    3602 </span>            : 
<span class="lineNum">    3603 </span>            : template&lt;typename _Tp&gt; inline size_t Seq&lt;_Tp&gt;::index(const _Tp&amp; elem) const
<span class="lineNum">    3604 </span>            : { return cvSeqElemIdx(seq, &amp;elem); }
<span class="lineNum">    3605 </span>            : 
<span class="lineNum">    3606 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::push_back(const _Tp&amp; elem)
<span class="lineNum">    3607 </span>            : { cvSeqPush(seq, &amp;elem); }
<span class="lineNum">    3608 </span>            : 
<span class="lineNum">    3609 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::push_front(const _Tp&amp; elem)
<span class="lineNum">    3610 </span>            : { cvSeqPushFront(seq, &amp;elem); }
<span class="lineNum">    3611 </span>            : 
<span class="lineNum">    3612 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::push_back(const _Tp* elem, size_t count)
<span class="lineNum">    3613 </span>            : { cvSeqPushMulti(seq, elem, (int)count, 0); }
<span class="lineNum">    3614 </span>            : 
<span class="lineNum">    3615 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::push_front(const _Tp* elem, size_t count)
<span class="lineNum">    3616 </span>            : { cvSeqPushMulti(seq, elem, (int)count, 1); }
<span class="lineNum">    3617 </span>            : 
<span class="lineNum">    3618 </span>            : template&lt;typename _Tp&gt; inline _Tp&amp; Seq&lt;_Tp&gt;::back()
<span class="lineNum">    3619 </span>            : { return *(_Tp*)getSeqElem(seq, -1); }
<span class="lineNum">    3620 </span>            : 
<span class="lineNum">    3621 </span>            : template&lt;typename _Tp&gt; inline const _Tp&amp; Seq&lt;_Tp&gt;::back() const
<span class="lineNum">    3622 </span>            : { return *(const _Tp*)getSeqElem(seq, -1); }
<span class="lineNum">    3623 </span>            : 
<span class="lineNum">    3624 </span>            : template&lt;typename _Tp&gt; inline _Tp&amp; Seq&lt;_Tp&gt;::front()
<span class="lineNum">    3625 </span>            : { return *(_Tp*)getSeqElem(seq, 0); }
<span class="lineNum">    3626 </span>            : 
<span class="lineNum">    3627 </span>            : template&lt;typename _Tp&gt; inline const _Tp&amp; Seq&lt;_Tp&gt;::front() const
<span class="lineNum">    3628 </span>            : { return *(const _Tp*)getSeqElem(seq, 0); }
<span class="lineNum">    3629 </span>            : 
<span class="lineNum">    3630 </span>            : template&lt;typename _Tp&gt; inline bool Seq&lt;_Tp&gt;::empty() const
<span class="lineNum">    3631 </span>            : { return !seq || seq-&gt;total == 0; }
<span class="lineNum">    3632 </span>            : 
<span class="lineNum">    3633 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::clear()
<span class="lineNum">    3634 </span>            : { if(seq) clearSeq(seq); }
<span class="lineNum">    3635 </span>            : 
<span class="lineNum">    3636 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::pop_back()
<span class="lineNum">    3637 </span>            : { seqPop(seq); }
<span class="lineNum">    3638 </span>            : 
<span class="lineNum">    3639 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::pop_front()
<span class="lineNum">    3640 </span>            : { seqPopFront(seq); }
<span class="lineNum">    3641 </span>            : 
<span class="lineNum">    3642 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::pop_back(_Tp* elem, size_t count)
<span class="lineNum">    3643 </span>            : { seqPopMulti(seq, elem, (int)count, 0); }
<span class="lineNum">    3644 </span>            : 
<span class="lineNum">    3645 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::pop_front(_Tp* elem, size_t count)
<span class="lineNum">    3646 </span>            : { seqPopMulti(seq, elem, (int)count, 1); }
<span class="lineNum">    3647 </span>            : 
<span class="lineNum">    3648 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::insert(int idx, const _Tp&amp; elem)
<span class="lineNum">    3649 </span>            : { seqInsert(seq, idx, &amp;elem); }
<span class="lineNum">    3650 </span>            : 
<span class="lineNum">    3651 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::insert(int idx, const _Tp* elems, size_t count)
<span class="lineNum">    3652 </span>            : {
<span class="lineNum">    3653 </span>            :     CvMat m = cvMat(1, count, DataType&lt;_Tp&gt;::type, elems);
<span class="lineNum">    3654 </span>            :     seqInsertSlice(seq, idx, &amp;m);
<span class="lineNum">    3655 </span>            : }
<span class="lineNum">    3656 </span>            : 
<span class="lineNum">    3657 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::remove(int idx)
<span class="lineNum">    3658 </span>            : { seqRemove(seq, idx); }
<span class="lineNum">    3659 </span>            : 
<span class="lineNum">    3660 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::remove(const Range&amp; r)
<span class="lineNum">    3661 </span>            : { seqRemoveSlice(seq, r); }
<span class="lineNum">    3662 </span>            : 
<span class="lineNum">    3663 </span>            : template&lt;typename _Tp&gt; inline void Seq&lt;_Tp&gt;::copyTo(vector&lt;_Tp&gt;&amp; vec, const Range&amp; range) const
<span class="lineNum">    3664 </span>            : {
<span class="lineNum">    3665 </span>            :     size_t len = !seq ? 0 : range == Range::all() ? seq-&gt;total : range.end - range.start;
<span class="lineNum">    3666 </span>            :     vec.resize(len);
<span class="lineNum">    3667 </span>            :     if( seq &amp;&amp; len )
<span class="lineNum">    3668 </span>            :         cvCvtSeqToArray(seq, &amp;vec[0], range);
<span class="lineNum">    3669 </span>            : }
<span class="lineNum">    3670 </span>            : 
<span class="lineNum">    3671 </span>            : template&lt;typename _Tp&gt; inline Seq&lt;_Tp&gt;::operator vector&lt;_Tp&gt;() const
<span class="lineNum">    3672 </span>            : {
<span class="lineNum">    3673 </span>            :     vector&lt;_Tp&gt; vec;
<span class="lineNum">    3674 </span>            :     copyTo(vec);
<span class="lineNum">    3675 </span>            :     return vec;
<span class="lineNum">    3676 </span>            : }
<span class="lineNum">    3677 </span>            : 
<span class="lineNum">    3678 </span>            : template&lt;typename _Tp&gt; inline SeqIterator&lt;_Tp&gt;::SeqIterator()
<span class="lineNum">    3679 </span>            : { memset(this, 0, sizeof(*this)); }
<span class="lineNum">    3680 </span>            : 
<span class="lineNum">    3681 </span>            : template&lt;typename _Tp&gt; inline SeqIterator&lt;_Tp&gt;::SeqIterator(const Seq&lt;_Tp&gt;&amp; _seq, bool seekEnd)
<span class="lineNum">    3682 </span>            : {
<span class="lineNum">    3683 </span>            :     cvStartReadSeq(_seq.seq, this);
<span class="lineNum">    3684 </span>            :     index = seekEnd ? _seq.seq-&gt;total : 0;
<span class="lineNum">    3685 </span>            : }
<span class="lineNum">    3686 </span>            : 
<span class="lineNum">    3687 </span>            : template&lt;typename _Tp&gt; inline void SeqIterator&lt;_Tp&gt;::seek(size_t pos)
<span class="lineNum">    3688 </span>            : {
<span class="lineNum">    3689 </span>            :     cvSetSeqReaderPos(this, (int)pos, false);
<span class="lineNum">    3690 </span>            :     index = pos;
<span class="lineNum">    3691 </span>            : }
<span class="lineNum">    3692 </span>            : 
<span class="lineNum">    3693 </span>            : template&lt;typename _Tp&gt; inline size_t SeqIterator&lt;_Tp&gt;::tell() const
<span class="lineNum">    3694 </span>            : { return index; }
<span class="lineNum">    3695 </span>            : 
<span class="lineNum">    3696 </span>            : template&lt;typename _Tp&gt; inline _Tp&amp; SeqIterator&lt;_Tp&gt;::operator *()
<span class="lineNum">    3697 </span>            : { return *(_Tp*)ptr; }
<span class="lineNum">    3698 </span>            : 
<span class="lineNum">    3699 </span>            : template&lt;typename _Tp&gt; inline const _Tp&amp; SeqIterator&lt;_Tp&gt;::operator *() const
<span class="lineNum">    3700 </span>            : { return *(const _Tp*)ptr; }
<span class="lineNum">    3701 </span>            : 
<span class="lineNum">    3702 </span>            : template&lt;typename _Tp&gt; inline SeqIterator&lt;_Tp&gt;&amp; SeqIterator&lt;_Tp&gt;::operator ++()
<span class="lineNum">    3703 </span>            : {
<span class="lineNum">    3704 </span>            :     CV_NEXT_SEQ_ELEM(sizeof(_Tp), *this);
<span class="lineNum">    3705 </span>            :     if( ++index &gt;= seq-&gt;total*2 )
<span class="lineNum">    3706 </span>            :         index = 0;
<span class="lineNum">    3707 </span>            :     return *this;
<span class="lineNum">    3708 </span>            : }
<span class="lineNum">    3709 </span>            : 
<span class="lineNum">    3710 </span>            : template&lt;typename _Tp&gt; inline SeqIterator&lt;_Tp&gt; SeqIterator&lt;_Tp&gt;::operator ++(int) const
<span class="lineNum">    3711 </span>            : {
<span class="lineNum">    3712 </span>            :     SeqIterator&lt;_Tp&gt; it = *this;
<span class="lineNum">    3713 </span>            :     ++*this;
<span class="lineNum">    3714 </span>            :     return it;
<span class="lineNum">    3715 </span>            : }
<span class="lineNum">    3716 </span>            : 
<span class="lineNum">    3717 </span>            : template&lt;typename _Tp&gt; inline SeqIterator&lt;_Tp&gt;&amp; SeqIterator&lt;_Tp&gt;::operator --()
<span class="lineNum">    3718 </span>            : {
<span class="lineNum">    3719 </span>            :     CV_PREV_SEQ_ELEM(sizeof(_Tp), *this);
<span class="lineNum">    3720 </span>            :     if( --index &lt; 0 )
<span class="lineNum">    3721 </span>            :         index = seq-&gt;total*2-1;
<span class="lineNum">    3722 </span>            :     return *this;
<span class="lineNum">    3723 </span>            : }
<span class="lineNum">    3724 </span>            : 
<span class="lineNum">    3725 </span>            : template&lt;typename _Tp&gt; inline SeqIterator&lt;_Tp&gt; SeqIterator&lt;_Tp&gt;::operator --(int) const
<span class="lineNum">    3726 </span>            : {
<span class="lineNum">    3727 </span>            :     SeqIterator&lt;_Tp&gt; it = *this;
<span class="lineNum">    3728 </span>            :     --*this;
<span class="lineNum">    3729 </span>            :     return it;
<span class="lineNum">    3730 </span>            : }
<span class="lineNum">    3731 </span>            : 
<span class="lineNum">    3732 </span>            : template&lt;typename _Tp&gt; inline SeqIterator&lt;_Tp&gt;&amp; SeqIterator&lt;_Tp&gt;::operator +=(int delta)
<span class="lineNum">    3733 </span>            : {
<span class="lineNum">    3734 </span>            :     cvSetSeqReaderPos(this, delta, 1);
<span class="lineNum">    3735 </span>            :     index += delta;
<span class="lineNum">    3736 </span>            :     int n = seq-&gt;total*2;
<span class="lineNum">    3737 </span>            :     if( index &lt; 0 )
<span class="lineNum">    3738 </span>            :         index += n;
<span class="lineNum">    3739 </span>            :     if( index &gt;= n )
<span class="lineNum">    3740 </span>            :         index -= n;
<span class="lineNum">    3741 </span>            :     return *this;
<span class="lineNum">    3742 </span>            : }
<span class="lineNum">    3743 </span>            : 
<span class="lineNum">    3744 </span>            : template&lt;typename _Tp&gt; inline SeqIterator&lt;_Tp&gt;&amp; SeqIterator&lt;_Tp&gt;::operator -=(int delta)
<span class="lineNum">    3745 </span>            : {
<span class="lineNum">    3746 </span>            :     return (*this += -delta);
<span class="lineNum">    3747 </span>            : }
<span class="lineNum">    3748 </span>            : 
<span class="lineNum">    3749 </span>            : template&lt;typename _Tp&gt; inline ptrdiff_t operator - (const SeqIterator&lt;_Tp&gt;&amp; a,
<span class="lineNum">    3750 </span>            :                                                     const SeqIterator&lt;_Tp&gt;&amp; b)
<span class="lineNum">    3751 </span>            : {
<span class="lineNum">    3752 </span>            :     ptrdiff_t delta = a.index - b.index, n = a.seq-&gt;total;
<span class="lineNum">    3753 </span>            :     if( std::abs(static_cast&lt;long&gt;(delta)) &gt; n )
<span class="lineNum">    3754 </span>            :         delta += delta &lt; 0 ? n : -n;
<span class="lineNum">    3755 </span>            :     return delta;
<span class="lineNum">    3756 </span>            : }
<span class="lineNum">    3757 </span>            : 
<span class="lineNum">    3758 </span>            : template&lt;typename _Tp&gt; inline bool operator == (const SeqIterator&lt;_Tp&gt;&amp; a,
<span class="lineNum">    3759 </span>            :                                                 const SeqIterator&lt;_Tp&gt;&amp; b)
<span class="lineNum">    3760 </span>            : {
<span class="lineNum">    3761 </span>            :     return a.seq == b.seq &amp;&amp; a.index == b.index;
<span class="lineNum">    3762 </span>            : }
<span class="lineNum">    3763 </span>            : 
<span class="lineNum">    3764 </span>            : template&lt;typename _Tp&gt; inline bool operator != (const SeqIterator&lt;_Tp&gt;&amp; a,
<span class="lineNum">    3765 </span>            :                                                 const SeqIterator&lt;_Tp&gt;&amp; b)
<span class="lineNum">    3766 </span>            : {
<span class="lineNum">    3767 </span>            :     return !(a == b);
<span class="lineNum">    3768 </span>            : }
<span class="lineNum">    3769 </span>            : 
<span class="lineNum">    3770 </span>            : 
<span class="lineNum">    3771 </span>            : template&lt;typename _ClsName&gt; struct RTTIImpl
<span class="lineNum">    3772 </span>            : {
<span class="lineNum">    3773 </span>            : public:
<span class="lineNum">    3774 </span>            :     static int isInstance(const void* ptr)
<span class="lineNum">    3775 </span>            :     {
<span class="lineNum">    3776 </span>            :         static _ClsName dummy;
<span class="lineNum">    3777 </span>            :         static void* dummyp = &amp;dummy;
<span class="lineNum">    3778 </span>            :         union
<span class="lineNum">    3779 </span>            :         {
<span class="lineNum">    3780 </span>            :             const void* p;
<span class="lineNum">    3781 </span>            :             const void** pp;
<span class="lineNum">    3782 </span>            :         } a, b;
<span class="lineNum">    3783 </span>            :         a.p = dummyp;
<span class="lineNum">    3784 </span>            :         b.p = ptr;
<span class="lineNum">    3785 </span>            :         return *a.pp == *b.pp;
<span class="lineNum">    3786 </span>            :     }
<span class="lineNum">    3787 </span>            :     static void release(void** dbptr)
<span class="lineNum">    3788 </span>            :     {
<span class="lineNum">    3789 </span>            :         if(dbptr &amp;&amp; *dbptr)
<span class="lineNum">    3790 </span>            :         {
<span class="lineNum">    3791 </span>            :             delete (_ClsName*)*dbptr;
<span class="lineNum">    3792 </span>            :             *dbptr = 0;
<span class="lineNum">    3793 </span>            :         }
<span class="lineNum">    3794 </span>            :     }
<span class="lineNum">    3795 </span>            :     static void* read(CvFileStorage* fs, CvFileNode* n)
<span class="lineNum">    3796 </span>            :     {
<span class="lineNum">    3797 </span>            :         FileNode fn(fs, n);
<span class="lineNum">    3798 </span>            :         _ClsName* obj = new _ClsName;
<span class="lineNum">    3799 </span>            :         if(obj-&gt;read(fn))
<span class="lineNum">    3800 </span>            :             return obj;
<span class="lineNum">    3801 </span>            :         delete obj;
<span class="lineNum">    3802 </span>            :         return 0;
<span class="lineNum">    3803 </span>            :     }
<span class="lineNum">    3804 </span>            : 
<span class="lineNum">    3805 </span>            :     static void write(CvFileStorage* _fs, const char* name, const void* ptr, CvAttrList)
<span class="lineNum">    3806 </span>            :     {
<span class="lineNum">    3807 </span>            :         if(ptr &amp;&amp; _fs)
<span class="lineNum">    3808 </span>            :         {
<span class="lineNum">    3809 </span>            :             FileStorage fs(_fs);
<span class="lineNum">    3810 </span>            :             fs.fs.addref();
<span class="lineNum">    3811 </span>            :             ((const _ClsName*)ptr)-&gt;write(fs, string(name));
<span class="lineNum">    3812 </span>            :         }
<span class="lineNum">    3813 </span>            :     }
<span class="lineNum">    3814 </span>            : 
<span class="lineNum">    3815 </span>            :     static void* clone(const void* ptr)
<span class="lineNum">    3816 </span>            :     {
<span class="lineNum">    3817 </span>            :         if(!ptr)
<span class="lineNum">    3818 </span>            :             return 0;
<span class="lineNum">    3819 </span>            :         return new _ClsName(*(const _ClsName*)ptr);
<span class="lineNum">    3820 </span>            :     }
<span class="lineNum">    3821 </span>            : };
<span class="lineNum">    3822 </span>            : 
<span class="lineNum">    3823 </span>            : 
<span class="lineNum">    3824 </span>            : class CV_EXPORTS Formatter
<span class="lineNum">    3825 </span>            : {
<span class="lineNum">    3826 </span>            : public:
<span class="lineNum">    3827 </span>            :     virtual ~Formatter() {}
<span class="lineNum">    3828 </span>            :     virtual void write(std::ostream&amp; out, const Mat&amp; m, const int* params=0, int nparams=0) const = 0;
<span class="lineNum">    3829 </span>            :     virtual void write(std::ostream&amp; out, const void* data, int nelems, int type,
<span class="lineNum">    3830 </span>            :                        const int* params=0, int nparams=0) const = 0;
<span class="lineNum">    3831 </span>            :     static const Formatter* get(const char* fmt=&quot;&quot;);
<span class="lineNum">    3832 </span>            :     static const Formatter* setDefault(const Formatter* fmt);
<span class="lineNum">    3833 </span>            : };
<span class="lineNum">    3834 </span>            : 
<span class="lineNum">    3835 </span>            : 
<span class="lineNum">    3836 </span>            : struct CV_EXPORTS Formatted
<span class="lineNum">    3837 </span>            : {
<span class="lineNum">    3838 </span>            :     Formatted(const Mat&amp; m, const Formatter* fmt,
<span class="lineNum">    3839 </span>            :               const vector&lt;int&gt;&amp; params);
<span class="lineNum">    3840 </span>            :     Formatted(const Mat&amp; m, const Formatter* fmt,
<span class="lineNum">    3841 </span>            :               const int* params=0);
<span class="lineNum">    3842 </span>            :     Mat mtx;
<span class="lineNum">    3843 </span>            :     const Formatter* fmt;
<span class="lineNum">    3844 </span>            :     vector&lt;int&gt; params;
<span class="lineNum">    3845 </span>            : };
<span class="lineNum">    3846 </span>            : 
<span class="lineNum">    3847 </span>            : static inline Formatted format(const Mat&amp; mtx, const char* fmt,
<span class="lineNum">    3848 </span>            :                                const vector&lt;int&gt;&amp; params=vector&lt;int&gt;())
<span class="lineNum">    3849 </span>            : {
<span class="lineNum">    3850 </span>            :     return Formatted(mtx, Formatter::get(fmt), params);
<span class="lineNum">    3851 </span>            : }
<span class="lineNum">    3852 </span>            : 
<span class="lineNum">    3853 </span>            : template&lt;typename _Tp&gt; static inline Formatted format(const vector&lt;Point_&lt;_Tp&gt; &gt;&amp; vec,
<span class="lineNum">    3854 </span>            :                                                       const char* fmt, const vector&lt;int&gt;&amp; params=vector&lt;int&gt;())
<span class="lineNum">    3855 </span>            : {
<span class="lineNum">    3856 </span>            :     return Formatted(Mat(vec), Formatter::get(fmt), params);
<span class="lineNum">    3857 </span>            : }
<span class="lineNum">    3858 </span>            : 
<span class="lineNum">    3859 </span>            : template&lt;typename _Tp&gt; static inline Formatted format(const vector&lt;Point3_&lt;_Tp&gt; &gt;&amp; vec,
<span class="lineNum">    3860 </span>            :                                                       const char* fmt, const vector&lt;int&gt;&amp; params=vector&lt;int&gt;())
<span class="lineNum">    3861 </span>            : {
<span class="lineNum">    3862 </span>            :     return Formatted(Mat(vec), Formatter::get(fmt), params);
<span class="lineNum">    3863 </span>            : }
<span class="lineNum">    3864 </span>            : 
<span class="lineNum">    3865 </span>            : /** \brief prints Mat to the output stream in Matlab notation
<span class="lineNum">    3866 </span>            :  * use like
<span class="lineNum">    3867 </span>            :  @verbatim
<span class="lineNum">    3868 </span>            :  Mat my_mat = Mat::eye(3,3,CV_32F);
<span class="lineNum">    3869 </span>            :  std::cout &lt;&lt; my_mat;
<span class="lineNum">    3870 </span>            :  @endverbatim
<span class="lineNum">    3871 </span>            :  */
<span class="lineNum">    3872 </span>            : static inline std::ostream&amp; operator &lt;&lt; (std::ostream&amp; out, const Mat&amp; mtx)
<span class="lineNum">    3873 </span>            : {
<span class="lineNum">    3874 </span>            :     Formatter::get()-&gt;write(out, mtx);
<span class="lineNum">    3875 </span>            :     return out;
<span class="lineNum">    3876 </span>            : }
<span class="lineNum">    3877 </span>            : 
<span class="lineNum">    3878 </span>            : /** \brief prints Mat to the output stream allows in the specified notation (see format)
<span class="lineNum">    3879 </span>            :  * use like
<span class="lineNum">    3880 </span>            :  @verbatim
<span class="lineNum">    3881 </span>            :  Mat my_mat = Mat::eye(3,3,CV_32F);
<span class="lineNum">    3882 </span>            :  std::cout &lt;&lt; my_mat;
<span class="lineNum">    3883 </span>            :  @endverbatim
<span class="lineNum">    3884 </span>            :  */
<span class="lineNum">    3885 </span>            : static inline std::ostream&amp; operator &lt;&lt; (std::ostream&amp; out, const Formatted&amp; fmtd)
<span class="lineNum">    3886 </span>            : {
<span class="lineNum">    3887 </span>            :     fmtd.fmt-&gt;write(out, fmtd.mtx);
<span class="lineNum">    3888 </span>            :     return out;
<span class="lineNum">    3889 </span>            : }
<span class="lineNum">    3890 </span>            : 
<span class="lineNum">    3891 </span>            : 
<span class="lineNum">    3892 </span>            : template&lt;typename _Tp&gt; static inline std::ostream&amp; operator &lt;&lt; (std::ostream&amp; out,
<span class="lineNum">    3893 </span>            :                                                                 const vector&lt;Point_&lt;_Tp&gt; &gt;&amp; vec)
<span class="lineNum">    3894 </span>            : {
<span class="lineNum">    3895 </span>            :     Formatter::get()-&gt;write(out, Mat(vec));
<span class="lineNum">    3896 </span>            :     return out;
<span class="lineNum">    3897 </span>            : }
<span class="lineNum">    3898 </span>            : 
<span class="lineNum">    3899 </span>            : 
<span class="lineNum">    3900 </span>            : template&lt;typename _Tp&gt; static inline std::ostream&amp; operator &lt;&lt; (std::ostream&amp; out,
<span class="lineNum">    3901 </span>            :                                                                 const vector&lt;Point3_&lt;_Tp&gt; &gt;&amp; vec)
<span class="lineNum">    3902 </span>            : {
<span class="lineNum">    3903 </span>            :     Formatter::get()-&gt;write(out, Mat(vec));
<span class="lineNum">    3904 </span>            :     return out;
<span class="lineNum">    3905 </span>            : }
<span class="lineNum">    3906 </span>            : 
<span class="lineNum">    3907 </span>            : 
<span class="lineNum">    3908 </span>            : /** Writes a Matx to an output stream.
<span class="lineNum">    3909 </span>            :  */
<span class="lineNum">    3910 </span>            : template&lt;typename _Tp, int m, int n&gt; inline std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Matx&lt;_Tp, m, n&gt;&amp; matx)
<span class="lineNum">    3911 </span>            : {
<span class="lineNum">    3912 </span>            :     out &lt;&lt; cv::Mat(matx);
<span class="lineNum">    3913 </span>            :     return out;
<span class="lineNum">    3914 </span>            : }
<span class="lineNum">    3915 </span>            : 
<span class="lineNum">    3916 </span>            : /** Writes a point to an output stream in Matlab notation
<span class="lineNum">    3917 </span>            :  */
<span class="lineNum">    3918 </span>            : template&lt;typename _Tp&gt; inline std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Point_&lt;_Tp&gt;&amp; p)
<span class="lineNum">    3919 </span>            : {
<span class="lineNum">    3920 </span>            :     out &lt;&lt; &quot;[&quot; &lt;&lt; p.x &lt;&lt; &quot;, &quot; &lt;&lt; p.y &lt;&lt; &quot;]&quot;;
<span class="lineNum">    3921 </span>            :     return out;
<span class="lineNum">    3922 </span>            : }
<span class="lineNum">    3923 </span>            : 
<span class="lineNum">    3924 </span>            : /** Writes a point to an output stream in Matlab notation
<span class="lineNum">    3925 </span>            :  */
<span class="lineNum">    3926 </span>            : template&lt;typename _Tp&gt; inline std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Point3_&lt;_Tp&gt;&amp; p)
<span class="lineNum">    3927 </span>            : {
<span class="lineNum">    3928 </span>            :     out &lt;&lt; &quot;[&quot; &lt;&lt; p.x &lt;&lt; &quot;, &quot; &lt;&lt; p.y &lt;&lt; &quot;, &quot; &lt;&lt; p.z &lt;&lt; &quot;]&quot;;
<span class="lineNum">    3929 </span>            :     return out;
<span class="lineNum">    3930 </span>            : }
<span class="lineNum">    3931 </span>            : 
<span class="lineNum">    3932 </span>            : /** Writes a Vec to an output stream. Format example : [10, 20, 30]
<span class="lineNum">    3933 </span>            :  */
<span class="lineNum">    3934 </span>            : template&lt;typename _Tp, int n&gt; inline std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Vec&lt;_Tp, n&gt;&amp; vec)
<span class="lineNum">    3935 </span>            : {
<span class="lineNum">    3936 </span>            :     out &lt;&lt; &quot;[&quot;;
<span class="lineNum">    3937 </span>            : 
<span class="lineNum">    3938 </span>            :     if(Vec&lt;_Tp, n&gt;::depth &lt; CV_32F)
<span class="lineNum">    3939 </span>            :     {
<span class="lineNum">    3940 </span>            :         for (int i = 0; i &lt; n - 1; ++i) {
<span class="lineNum">    3941 </span>            :             out &lt;&lt; (int)vec[i] &lt;&lt; &quot;, &quot;;
<span class="lineNum">    3942 </span>            :         }
<span class="lineNum">    3943 </span>            :         out &lt;&lt; (int)vec[n-1] &lt;&lt; &quot;]&quot;;
<span class="lineNum">    3944 </span>            :     }
<span class="lineNum">    3945 </span>            :     else
<span class="lineNum">    3946 </span>            :     {
<span class="lineNum">    3947 </span>            :         for (int i = 0; i &lt; n - 1; ++i) {
<span class="lineNum">    3948 </span>            :             out &lt;&lt; vec[i] &lt;&lt; &quot;, &quot;;
<span class="lineNum">    3949 </span>            :         }
<span class="lineNum">    3950 </span>            :         out &lt;&lt; vec[n-1] &lt;&lt; &quot;]&quot;;
<span class="lineNum">    3951 </span>            :     }
<span class="lineNum">    3952 </span>            : 
<span class="lineNum">    3953 </span>            :     return out;
<span class="lineNum">    3954 </span>            : }
<span class="lineNum">    3955 </span>            : 
<span class="lineNum">    3956 </span>            : /** Writes a Size_ to an output stream. Format example : [640 x 480]
<span class="lineNum">    3957 </span>            :  */
<span class="lineNum">    3958 </span>            : template&lt;typename _Tp&gt; inline std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Size_&lt;_Tp&gt;&amp; size)
<span class="lineNum">    3959 </span>            : {
<span class="lineNum">    3960 </span>            :     out &lt;&lt; &quot;[&quot; &lt;&lt; size.width &lt;&lt; &quot; x &quot; &lt;&lt; size.height &lt;&lt; &quot;]&quot;;
<span class="lineNum">    3961 </span>            :     return out;
<span class="lineNum">    3962 </span>            : }
<span class="lineNum">    3963 </span>            : 
<span class="lineNum">    3964 </span>            : /** Writes a Rect_ to an output stream. Format example : [640 x 480 from (10, 20)]
<span class="lineNum">    3965 </span>            :  */
<span class="lineNum">    3966 </span>            : template&lt;typename _Tp&gt; inline std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Rect_&lt;_Tp&gt;&amp; rect)
<span class="lineNum">    3967 </span>            : {
<span class="lineNum">    3968 </span>            :     out &lt;&lt; &quot;[&quot; &lt;&lt; rect.width &lt;&lt; &quot; x &quot; &lt;&lt; rect.height &lt;&lt; &quot; from (&quot; &lt;&lt; rect.x &lt;&lt; &quot;, &quot; &lt;&lt; rect.y &lt;&lt; &quot;)]&quot;;
<span class="lineNum">    3969 </span>            :     return out;
<span class="lineNum">    3970 </span>            : }
<span class="lineNum">    3971 </span>            : 
<span class="lineNum">    3972 </span>            : 
<span class="lineNum">    3973 </span>            : template&lt;typename _Tp&gt; inline Ptr&lt;_Tp&gt; Algorithm::create(const string&amp; name)
<span class="lineNum">    3974 </span>            : {
<span class="lineNum">    3975 </span>            :     return _create(name).ptr&lt;_Tp&gt;();
<span class="lineNum">    3976 </span>            : }
<span class="lineNum">    3977 </span>            : 
<span class="lineNum">    3978 </span>            : template&lt;typename _Tp&gt;
<span class="lineNum">    3979 </span>            : inline void Algorithm::set(const char* _name, const Ptr&lt;_Tp&gt;&amp; value)
<span class="lineNum">    3980 </span>            : {
<span class="lineNum">    3981 </span>            :     Ptr&lt;Algorithm&gt; algo_ptr = value. template ptr&lt;cv::Algorithm&gt;();
<span class="lineNum">    3982 </span>            :     if (algo_ptr.empty()) {
<span class="lineNum">    3983 </span>            :         CV_Error( CV_StsUnsupportedFormat, &quot;unknown/unsupported Ptr type of the second parameter of the method Algorithm::set&quot;);
<span class="lineNum">    3984 </span>            :     }
<span class="lineNum">    3985 </span>            :     info()-&gt;set(this, _name, ParamType&lt;Algorithm&gt;::type, &amp;algo_ptr);
<span class="lineNum">    3986 </span>            : }
<span class="lineNum">    3987 </span>            : 
<span class="lineNum">    3988 </span>            : template&lt;typename _Tp&gt;
<span class="lineNum">    3989 </span>            : inline void Algorithm::set(const string&amp; _name, const Ptr&lt;_Tp&gt;&amp; value)
<span class="lineNum">    3990 </span>            : {
<span class="lineNum">    3991 </span>            :     this-&gt;set&lt;_Tp&gt;(_name.c_str(), value);
<span class="lineNum">    3992 </span>            : }
<span class="lineNum">    3993 </span>            : 
<span class="lineNum">    3994 </span>            : template&lt;typename _Tp&gt;
<span class="lineNum">    3995 </span>            : inline void Algorithm::setAlgorithm(const char* _name, const Ptr&lt;_Tp&gt;&amp; value)
<span class="lineNum">    3996 </span>            : {
<span class="lineNum">    3997 </span>            :     Ptr&lt;Algorithm&gt; algo_ptr = value. template ptr&lt;cv::Algorithm&gt;();
<span class="lineNum">    3998 </span>            :     if (algo_ptr.empty()) {
<span class="lineNum">    3999 </span>            :         CV_Error( CV_StsUnsupportedFormat, &quot;unknown/unsupported Ptr type of the second parameter of the method Algorithm::set&quot;);
<span class="lineNum">    4000 </span>            :     }
<span class="lineNum">    4001 </span>            :     info()-&gt;set(this, _name, ParamType&lt;Algorithm&gt;::type, &amp;algo_ptr);
<span class="lineNum">    4002 </span>            : }
<span class="lineNum">    4003 </span>            : 
<span class="lineNum">    4004 </span>            : template&lt;typename _Tp&gt;
<span class="lineNum">    4005 </span>            : inline void Algorithm::setAlgorithm(const string&amp; _name, const Ptr&lt;_Tp&gt;&amp; value)
<span class="lineNum">    4006 </span>            : {
<span class="lineNum">    4007 </span>            :     this-&gt;set&lt;_Tp&gt;(_name.c_str(), value);
<span class="lineNum">    4008 </span>            : }
<span class="lineNum">    4009 </span>            : 
<span class="lineNum">    4010 </span>            : template&lt;typename _Tp&gt; inline typename ParamType&lt;_Tp&gt;::member_type Algorithm::get(const string&amp; _name) const
<span class="lineNum">    4011 </span>            : {
<span class="lineNum">    4012 </span>            :     typename ParamType&lt;_Tp&gt;::member_type value;
<span class="lineNum">    4013 </span>            :     info()-&gt;get(this, _name.c_str(), ParamType&lt;_Tp&gt;::type, &amp;value);
<span class="lineNum">    4014 </span>            :     return value;
<span class="lineNum">    4015 </span>            : }
<span class="lineNum">    4016 </span>            : 
<span class="lineNum">    4017 </span>            : template&lt;typename _Tp&gt; inline typename ParamType&lt;_Tp&gt;::member_type Algorithm::get(const char* _name) const
<span class="lineNum">    4018 </span>            : {
<span class="lineNum">    4019 </span>            :     typename ParamType&lt;_Tp&gt;::member_type value;
<span class="lineNum">    4020 </span>            :     info()-&gt;get(this, _name, ParamType&lt;_Tp&gt;::type, &amp;value);
<span class="lineNum">    4021 </span>            :     return value;
<span class="lineNum">    4022 </span>            : }
<span class="lineNum">    4023 </span>            : 
<span class="lineNum">    4024 </span>            : template&lt;typename _Tp, typename _Base&gt; inline void AlgorithmInfo::addParam(Algorithm&amp; algo, const char* parameter,
<span class="lineNum">    4025 </span>            :                   Ptr&lt;_Tp&gt;&amp; value, bool readOnly, Ptr&lt;_Tp&gt; (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr&lt;_Tp&gt;&amp;),
<span class="lineNum">    4026 </span>            :                   const string&amp; help)
<span class="lineNum">    4027 </span>            : {
<span class="lineNum">    4028 </span>            :     //TODO: static assert: _Tp inherits from _Base
<span class="lineNum">    4029 </span>            :     addParam_(algo, parameter, ParamType&lt;_Base&gt;::type, &amp;value, readOnly,
<span class="lineNum">    4030 </span>            :               (Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
<span class="lineNum">    4031 </span>            : }
<span class="lineNum">    4032 </span>            : 
<span class="lineNum">    4033 </span>            : template&lt;typename _Tp&gt; inline void AlgorithmInfo::addParam(Algorithm&amp; algo, const char* parameter,
<span class="lineNum">    4034 </span>            :                   Ptr&lt;_Tp&gt;&amp; value, bool readOnly, Ptr&lt;_Tp&gt; (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr&lt;_Tp&gt;&amp;),
<span class="lineNum">    4035 </span>            :                   const string&amp; help)
<span class="lineNum">    4036 </span>            : {
<span class="lineNum">    4037 </span>            :     //TODO: static assert: _Tp inherits from Algorithm
<span class="lineNum">    4038 </span>            :     addParam_(algo, parameter, ParamType&lt;Algorithm&gt;::type, &amp;value, readOnly,
<span class="lineNum">    4039 </span>            :               (Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
<span class="lineNum">    4040 </span>            : }
<span class="lineNum">    4041 </span>            : 
<span class="lineNum">    4042 </span>            : }
<span class="lineNum">    4043 </span>            : 
<span class="lineNum">    4044 </span>            : #ifdef _MSC_VER
<span class="lineNum">    4045 </span>            : # pragma warning(pop)
<span class="lineNum">    4046 </span>            : #endif
<span class="lineNum">    4047 </span>            : 
<span class="lineNum">    4048 </span>            : #endif // __cplusplus
<span class="lineNum">    4049 </span>            : #endif
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
